Change of UITextField placeholder color

后端 未结 13 1756
别跟我提以往
别跟我提以往 2021-01-30 06:09

How to dynamically change placeholder color of the UITextField? This is always the same system color.

No option in xib editor.

13条回答
  •  难免孤独
    2021-01-30 06:51

    I use this in SWIFT:

    myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder", attributes: [NSForegroundColorAttributeName : UIColor.redColor()])

    It seems that this works for others... I have no idea why it haven't worked for me before... maybe some project settings. Thanks for the comments. Currently I have no way how to test it again.

    Obsolete: But I don't know why, text is applied correctly, but placeholder color remains same (black/gray).

    --iOS8

提交回复
热议问题