美文网首页
UITextField数字键盘上添加完成按钮

UITextField数字键盘上添加完成按钮

作者: KeepOnline | 来源:发表于2018-12-27 11:34 被阅读10次
- (void)addDoneButtonForTF:(UITextField *)tf {
 
    UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 60, 7, 50, 30)];
    [button setTitle:@"完成"forState:UIControlStateNormal];
    [button setTitleColor:TotalBackGroundColor forState:UIControlStateNormal];
    [button addTarget:self action:@selector(hideKeyboard) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *flbSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithCustomView:button];
                bar.items = @[flbSpace, doneItem];
                tf.inputAccessoryView = bar;
                
}

相关文章

网友评论

      本文标题:UITextField数字键盘上添加完成按钮

      本文链接:https://www.haomeiwen.com/subject/zpkrlqtx.html