- (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;
}
网友评论