本文主要是介绍UITextField+Category,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import “UITextField+Category.h”
@implementation UITextField (Category)
- (void)setTextFieldInputAccessoryView{
UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
[topView setBarStyle:UIBarStyleDefault];
UIBarButtonItem * spaceBtn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[doneBtn setTitle:@”完成” forState:UIControlStateNormal];
doneBtn.frame = CGRectMake(2, 5, 40, 25);
[doneBtn addTarget:self action:@selector(dealKeyboardHide) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *doneBtnItem = [[UIBarButtonItem alloc]initWithCustomView:doneBtn];
NSArray * buttonsArray = [NSArray arrayWithObjects:spaceBtn,doneBtnItem,nil];
[topView setItems:buttonsArray];
[self setInputAccessoryView:topView];
[self setAutocorrectionType:UITextAutocorrectionTypeNo];
[self setAutocapitalizationType:UITextAutocapitalizationTypeNone];
}
- (void)dealKeyboardHide {
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
@end
这篇关于UITextField+Category的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!