How to set the color of the place holder text for a UITextField while preserving its existing properties?

前端 未结 5 936
没有蜡笔的小新
没有蜡笔的小新 2021-02-18 18:37

I have seen some answers that show how to change the placeHolder text color for UITextField by overriding the drawPlaceholderInRect: method such as this one:

iPhone UITe

5条回答
  •  鱼传尺愫
    2021-02-18 19:04

    From iOS 6,

    Without any subclassing, one can accomplish this with a couple lines of code like so:

    UIColor *color = [UIColor blackColor];
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: color}];
    

提交回复
热议问题