ios - 可以单独给UITextField中的placeholder设置字体大小吗?
高洛峰
高洛峰 2017-04-18 09:06:15
0
4
483

如题,应用中,有一处 TextField 需要填写数字,所以宽度比较窄,但是 placeholder 的提示语想使用中文:“请填写数字:”,导致比较宽,显示不全。不改变所输入文字的字体大小的前提下,是否可以单独设置 placeholder 的字体大小?

网上能查到的解决方案:

textField.placeholder = @"username is in here!";  
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; 

经过试验,好像已经失效了……

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

Antworte allen(4)
巴扎黑

失效是因为找不到这个属性的.textcolor .font 属性,可以打印看看有没有东西。

迷茫

我在分类里设置:

[self setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
[self setValue:[UIFont systemFontOfSize:15.f weight:UIFontWeightThin] forKeyPath:@"_placeholderLabel.font"];

可以的啊

PHPzhong

attributedPlaceholder属性?

黄舟

嗯,attributedPlaceholder属性

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage