- 修改placeholder的字体颜色、大小
[textField setValue:[UIColor redColor] forKeyPath:@”_placeholderLabel.textColor”];
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@”_placeholderLabel.font”];
- 修改光标的颜色
方法1:
[[UITextField appearance] setTintColor:[UIColor blackColor]];
//这种方法将影响所有TextField。
方法2:
textField.tintColor = [UIColor redColor];//影响指定光标颜色
以上方法如果在InterfaceBuilder中修改View的TintColor属性并不好用。
- 获取软键盘的高度
- (void)viewDidLoad
{
[super viewDidLoad];
//增加监听,当键盘出现或改变时收出消息
[[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];
int height = keyboardRect.size.height;
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
}