首页 > 其他 > 详细

设置UITextField占位符的颜色和字体

时间:2016-01-18 20:40:47      阅读:3227      评论:0      收藏:0      [点我收藏+]

今天刚学了UITextField控件, 感觉在里面设置占位符非常好, 给用户提示信息, 于是就在想占位符的字体和颜色能不能改变呢?

下面是小编的一些简单的实现.

主要有两种方法:

方法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功能很多呦, 还可以实现数组简单的求和

NSArray *dataArray = @[@"1", @"2", @"3", @"4", @"5"];

 NSNumber *sum = [dataArray valueForKeyPath:@"@sum.integerValue"];

 NSLog(@"%@", sum);

 

 
 

设置UITextField占位符的颜色和字体

原文:http://www.cnblogs.com/hsxblog/p/5140368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!