第一步先用xib画出来页面,并且拖出来关系
第二步在.m文件中写方法
注:此处用于直接粘贴,与图片代码相同
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.contentTV.delegate = self;
//字体大小
self.contentTV.font= [UIFont systemFontOfSize:16];
//添加滚动区域
// self.contentTV.contentInset= UIEdgeInsetsMake(-11, -6, 0, 0);
//是否可以滚动
self.contentTV.scrollEnabled = NO;
//获得第一响应者身份
[self.contentTV becomeFirstResponder];
//返回键的类型
self.contentTV.returnKeyType = UIReturnKeyDefault;
//键盘类型
self.contentTV.keyboardType = UIKeyboardTypeDefault;
UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
//设置style
[topView setBarStyle:UIBarStyleDefault];
//设置圆角
[self.contentTV.layer setCornerRadius:5];
//定义两个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.contentTV setInputAccessoryView:topView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-
(void)resignKeyboard
{
[self.contentTV resignFirstResponder];
}