ios修改textField的小技巧

来源:互联网 发布:飞秋for mac 下载 编辑:程序博客网 时间:2024/05/22 00:45
  • 修改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:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];//增加监听,当键退出时收出消息[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotificationobject: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{} 
0 0
原创粉丝点击