码迷,mamicode.com
首页 > 其他好文 > 详细

键盘输入完成按钮

时间:2016-06-23 21:54:06      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:


- (void)addKeyboardNSNotification {
   
    UIToolbar *topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
   
    //设置style
    [topView  setBarStyle:UIBarStyleBlack];
   
    //定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边
    UIBarButtonItem  *button1 =[[UIBarButtonItem  alloc]initWithBarButtonSystemItem:                                        UIBarButtonSystemItemFlexibleSpace target:self action:nil];
   
    UIBarButtonItem *button2 = [[UIBarButtonItem  alloc]initWithBarButtonSystemItem:                                        UIBarButtonSystemItemFlexibleSpace target:self action:nil];
   
    //定义完成按钮
    UIBarButtonItem  *doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)];
   
    //在toolBar上加上这些按钮
    NSArray  *buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
   
    [topView setItems:buttonsArray];
   
    [self.user_field  setInputAccessoryView:topView];
    [self.psd_field setInputAccessoryView:topView];
   
}


//隐藏键盘
-(void)resignKeyboard {
    [self.user_field resignFirstResponder];
    [self.psd_field resignFirstResponder];
}

 

键盘输入完成按钮

标签:

原文地址:http://www.cnblogs.com/tony0571/p/5612098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!