iOS修改UITextField的Placeholder字体颜色

修改UITextField的Placeholder字体颜色有一下两张方式可以达到效果。

第一种:

UIColor *color = [UIColor whiteColor];

textfield.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];

第二种:

[textfield setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

  

时间: 2024-08-10 14:59:45

iOS修改UITextField的Placeholder字体颜色的相关文章

iOS利用storyboard修改UITextField的placeholder文字颜色

最近有个需求需要修改UITextField的placeholder文字颜色,在网上找发现有用代码修改的,但是考虑到更加优雅的实现,所以尝试着在storyboard中直接实现,结果竟然真的成功了(原谅我太小白),实现的位置如下: 具体步骤: 1.在User Defined Runtime Attributes中添加一个Key. 2.输入Key Path(这里我们输入_placeholderLabel.textColor). 3.选择Type,有很多种(这里我们选择Color) 4.设置Value(

ios 设置UITextField的placeholder大小颜色

需求:产品嫌弃placeholder的字体太大,颜色太明显,要求跟正常输入时的字体及颜色不同 方法:设置placeholder的大小和颜色,实际上是设置placeholder的label的大小和颜色,但是当设置完之后,placeholder的字体有点偏上了,所以设置一下属性. // 设置placeholder的字体大小 [titleField setValue:[UIFont systemFontOfSize:13] forKeyPath:@"_placeholderLabel.font&quo

修改UITextfield的Placeholder字体的颜色

版权声明:本文为博主原创文章,未经博主允许不得转载.

iOS学习-UITextField设置placeholder的颜色

UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(50, 200, 200, 40)]; text.borderStyle = UITextBorderStyleRoundedRect; NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:@"密码"]; [attribut

textFiled的placeHolder字体颜色

[email protected]"修改UITextField的placeholder字体颜色"; UITextField *textTF=[[UITextField alloc]initWithFrame:CGRectMake(20,130,300,30)]; [email protected]"修改UITextField的placeholder字体颜色"; //    // 一种方式 //    [textTF setValue:[UIColor redColo

[BS-19]更改UITextField的placeholder文字颜色的5种方法

更改UITextField的placeholder文字颜色的5种方法 想要达到的目标是:一个页面上有多个UITextField,当用户聚焦某textField时,该文本框的placeholder的文字会灰色变为白色,当文本框失去焦点时,placeholder颜色从白色再变回灰色. 1.放置UILabel 最简单最笨的方法是在每个textField里放一个UILabel来充当placeholder,当该textField聚焦时,让placeholder的文字会灰色变为白色,失焦后从白色再变回灰色.

(iOS)修改UITextField高度

修改UITextField高度 === --- ## 是否可以通过修改frame改变高度 网上流传的代码中使用如下一份代码: //    以下代码任然不能改变UITextField高度 CGRect rect = _userNameField.bounds; rect.size.height = 88; rect.size.width = 20; _userNameField.bounds = rect; 所以不可以. --- ## 通过自定义子类实现修改UITextField高度 在子类中覆盖

Android Them+SharedPreferences 修改程序所有view字体颜色、大小和页面背景

有这么一个需求,可以对页面的样式进行选择,然后根据选择改变程序所有字体颜色和页面背景.同时下一次启动程序,当前设置依然有效. 根据需求,我们需要一种快速,方便,有效的方式来实现需求,然后可以通过Android Them + SharedPreferences 来实现需求.Them用于存放设置的每一种样式,并应用于程序中,SharedPreferences用于记住程序当前的样式,根据SharedPreferences的内容来设置程序的样式,实现下次启动能够oncreat当前的样式设置. 这里的Th

iOS:UILabel设置不同字体颜色

NSString *str = @"0123456789";//label内容 NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:str]; //根据下标索引设置字体颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];