UITextField继承UIControlhtml
1.文字永远是一行,不能显示多行文字ios
2.有placehoder属性设置占位文字app
3.继承自UIControlide
4.监听行为布局
1> 设置代理动画
2> addTarget:action:forControlEvents:spa
3> 通知:UITextFieldTextDidChangeNotification代理
UITextView继承UIScrollViewserver
1.能显示任意行文字htm
2.不能设置占位文字(能够经过建立个UILabel子控件来加载在UITextView上实现)
3.继承自UIScollView
4.监听行为
1> 设置代理
2> 通知:UITextViewTextDidChangeNotification
相同点:二者均可以监听系统键盘的变化,能够据此自定义键盘:注意:二者在点击编辑内容时,系统 自动加载系统键盘,要想自定义键盘,必须先取消第一响应者[UITextView / UITextField resignFirstResponder],而后设置inputView;若是想实现自定义键盘和系统的键盘的自由切换,须要在设置inputView时,这样设置:textView.inputView = textView.inputView == nil ? emoticonKeyboardView : nil,而后恢复第一响应者[UITextView / UITextField becomeFirstResponder],便可实现键盘的自由切换。
使用场景:
键盘监听代码以下:(self.toolBar是自定义的键盘,继承至UIToolBar)
- (void)regiserNotification{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)keyboardWillChange:(NSNotification *)notification{
NSLog(@"%@",notification);
CGRect rect = [[[notification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSLog(@"%f---",rect.origin.y);
CGFloat offsetY = - kScreenHeight + rect.origin.y;
NSLog(@"---offsetY %f",offsetY);
[self.toolBar mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(offsetY);
}];
[self.view layoutIfNeeded];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}