设置UITextField占位符的颜色和字体
今天剛學(xué)了UITextField控件, 感覺在里面設(shè)置占位符非常好, 給用戶提示信息, 于是就在想占位符的字體和顏色能不能改變呢?
下面是小編的一些簡單的實(shí)現(xiàn).
主要有兩種方法:
方法1:利用富文本
@property (weak, nonatomic) IBOutlet UITextField *textField;
?NSDictionary *dic = @{NSForegroundColorAttributeName:[UIColor magentaColor], NSFontAttributeName:[UIFont systemFontOfSize:15]};
?self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"歡迎回來" attributes:dic];
?self.textField.tintColor = [UIColor cyanColor];
?
方法2:KVC
self.textField.placeholder = @"歡迎回來!";
?[self.textField setValue:[UIColor magentaColor] forKeyPath:@"_placeholderLabel.textColor"]
?[self.textField setValue:[UIFont systemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
?self.textField.tintColor = [UIColor greenColor];
?
KVC功能很多呦, 還可以實(shí)現(xiàn)數(shù)組簡單的求和
NSArray *dataArray = @[@"1", @"2", @"3", @"4", @"5"];
?NSNumber *sum = [dataArray valueForKeyPath:@"@sum.integerValue"];
?NSLog(@"%@", sum);
轉(zhuǎn)載于:https://www.cnblogs.com/YhhMzl/p/5038865.html
總結(jié)
以上是生活随笔為你收集整理的设置UITextField占位符的颜色和字体的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2015音乐播放器排行榜
- 下一篇: 怎么在手机百度上绑定自己的银行卡