- 点击textFiled的时候不让系统的键盘弹出。
//在textField开始编辑的时候
self.inputView = [[UIView alloc] initWithFrame:CGRectZero];
- 让textFile点击之后弹出自己想要的输入框
//自定义的一个view
self.inputView = [XXCalculator calculator];
这里要注意,这个自定义的view最好就是一个简简单单的view,我开始把这个view加到一个父view的时候(之前是为了封装这个view)就一直报错:“<UICompatibilityInputViewController: 0x14f9c6850> should have parent view controller: xxx but requested parent is:<UIInputWindowController: xxx>'”
很奇怪一点,当换成自己的输入view之后,不再响应editChange方法,不过editBegin方法还是可以响应。
当tableView中有textFiled的时候,此时键盘遮挡了textFiled,可以使用以下方法(让tableView的高度整体上移)
- (void)setTXListener {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
float height = keyboardRect.size.height;
self.setTable.contentOffset = CGPointMake(0, height);
}
- (void)keyboardWillHide:(NSNotification *)aNotification{
self.setTable.contentOffset = CGPointMake(0, 0);
}
- 改变textFiled的placeholder的颜色和大小,用sb的话,可以在sb的inspector中的User Defined Runtime Attributes 中通过keyPath的方式添加属性 参考下图
修改textFiled的placeholder属性.png
//代码设置
textField.placeholder = @"手机号码";
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];