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

前端 未结 5 939
没有蜡笔的小新
没有蜡笔的小新 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:11

    The safe way to customize UITextField’s placeholder is subclassing the UITextField and overriding placeholderRectForBounds:, Apple won’t bother you on this one. However, if you want to take the risk, you can try this way:

    [self.MyTextField setValue:[UIColor darkGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    

    Source.

提交回复
热议问题