设置placeholder字体颜色
声明TextField时,往往由于背景的原因,默认的placeholder字体颜色不够清晰,这里是直接设置placeholder的颜色属性
- //搜索框设置
- UITextField *searchTxt = [[UITextField alloc] initWithFrame:CGRectMake(15, 58, 260, 30)];
- [searchTxt setBackground:[UIImage imageNamed:@"inPutBackground.jpg"]];
- //设置提示字符
- [searchTxt setPlaceholder:@"请输入关键字..."];
- bsp; //设置placeholder的颜色,其中的_placeholderLabel.textColor是系统自带的,可以直接使用
- [searchTxt setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
- //设置光标颜色
- [searchTxt setTintColor:[UIColor whiteColor]];
- //设置输入字体颜色
- [searchTxt setTextColor:[UIColor whiteColor]];
- [self.view addSubview:searchTxt];
附图:
默认时效果
设置后效果
注:随手笔记,不严谨,以后发现错误立即更改
转载:http://blog.csdn.net/wsyx768/article/details/19755955
效果图:

代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 50)];
//UITextField设置placeholder颜色
UIColor *color = [UIColor redColor];
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSForegroundColorAttributeName: color}];
textField.delegate=self;
[self.view addSubview:textField];
}
本文介绍如何在iOS开发中使用UITextField并设置其placeholder的颜色属性。通过简单的代码示例展示了如何改变默认颜色以提高显示清晰度。
528

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



