这是第一种,添加属性
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSForegroundColorAttributeName] = [UIColor redColor];
NSAttributedString *string = [[NSAttributedString alloc]initWithString:@"cdcdcdcdcd" attributes:dict];
UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(30,230,120, 33)];
field.attributedPlaceholder = string;
[self.view addSubview:field];
[field setValue:[UIColor greenColor] forKeyPath:@"_placeholderLabel.textColor"];
[field setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
本文介绍两种方法来改变UITextField中占位符的颜色和字体大小:一种是通过为NSAttributedString添加属性,另一种是使用KVC(Key-Value Coding)直接设置属性。
3776

被折叠的 条评论
为什么被折叠?



