UITextField数字键盘添加完成按钮

设置键盘的附件 _intoTextField.inputAccessoryView = self.toolbar;

- (UIToolbar *)toolbar {
    if (_toolbar == nil) {
        _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 35)];
        _toolbar.tintColor = UIColorFrom0X(0xffae16);
        UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        UIBarButtonItem *commit = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone)];
        _toolbar.items = @[space, commit];
    }
    return _toolbar;
}

顺便赠送个颜色宏 不谢
#define UIColorFrom0X(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1]

你可能感兴趣的:(UITextField数字键盘添加完成按钮)