#inputView
inputView就是显示键盘的view,
如果重写这个view则不再弹出键盘,而是弹出自己的view.
如果想实现当某一控件变为第一响应者时不弹出键盘而是弹出我们自定义的界面,
那么我们就可以通过修改这个inputView来实现,比如弹出一个日期拾取器,或者自定义表情键盘。
#特性
inputView不会随着键盘出现而出现,
设置了InputView只会当UITextField或者UITextView变为第一相应者时显示出来,不会显示键盘了。
#InputAccessoryView
设置了InputAccessoryView,
它会随着键盘一起出现并且会显示在键盘的顶端。
#InutAccessoryView默认为nil.
_YGTextField.inputView = myview
_YGTextField.inputAccessoryView = _YGAccessoryView;
_YGTextField = [[UITextField alloc]initWithFrame:CGRectMake(100, 200, 180, 30)];
_YGTextField.backgroundColor = [UIColor lightGrayColor];
_YGTextField.placeholder = @"输入框";
[self.view addSubview:_YGTextField];
_YGAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
_YGAccessoryView.backgroundColor = [UIColor grayColor];
_YGTextField.inputAccessoryView = _YGAccessoryView;
UILabel * YGAccessoryLab = [[UILabel alloc]initWithFrame:CGRectMake(20, 10, 200, 15)];
YGAccessoryLab.text = @"YGAccessoryView";
[_YGAccessoryView addSubview:YGAccessoryLab];
_YGInputView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 200)];
_YGInputView.backgroundColor = [UIColor cyanColor];
_YGTextField.inputView = _YGInputView;
UILabel * YGInputLab = [[UILabel alloc]initWithFrame:CGRectMake(40, 50, 200, 15)];
YGInputLab.text = @"YGInputView";
[_YGInputView addSubview:YGInputLab];
-
效果如下图
-
只设置 inputAccessoryView
-
设置 inputAccessoryView和inputView
【code_小马】更多iOS实用战术