Changing Placeholder Text Color with Swift

前端 未结 30 2545
独厮守ぢ
独厮守ぢ 2020-11-29 15:57

I have a design that implements a dark blue UITextField, as the placeholder text is by default a dark grey colour I can barely make out what the place holder te

30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 16:07

    Use this for adding an attributed placeholder:

    let attributes : [String : Any]  = [ NSForegroundColorAttributeName: UIColor.lightGray,
                                         NSFontAttributeName : UIFont(name: "Helvetica Neue Light Italic", size: 12.0)!
                                       ]
    x_textfield.attributedPlaceholder = NSAttributedString(string: "Placeholder Text", attributes:attributes)
    

提交回复
热议问题