search

Home  >  Q&A  >  body text

ios - 可以单独给UITextField中的placeholder设置字体大小吗?

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

网上能查到的解决方案:

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

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

高洛峰高洛峰2889 days ago485

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:08:15

    The failure is because the .textcolor .font attribute of this attribute cannot be found. You can print it to see if there is anything.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:08:15

    I set it in the category:

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

    It’s ok

    reply
    0
  • PHPz

    PHPz2017-04-18 09:08:15

    attributedPlaceholder attribute?

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:08:15

    Well, attributedPlaceholder attribute

    reply
    0
  • Cancelreply