Change of UITextField placeholder color

后端 未结 13 1526
别跟我提以往
别跟我提以往 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:46

    @DogCoffee's answer in Swift would be

    let placeholderAttrs = [ NSForegroundColorAttributeName : UIColor.redColor()]
    let placeholder = NSAttributedString(string: "Some text", attributes: placeholderAttrs)
    
    textField.attributedPlaceholder = placeholder
    

提交回复
热议问题