Changing Placeholder Text Color with Swift

前端 未结 30 2546
独厮守ぢ
独厮守ぢ 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:20

    Create UITextField Extension like this:

    extension UITextField{
       @IBInspectable var placeHolderColor: UIColor? {
            get {
                return self.placeHolderColor
            }
            set {
                self.attributedPlaceholder = NSAttributedString(string:self.placeholder != nil ? self.placeholder! : "", attributes:[NSAttributedString.Key.foregroundColor: newValue!])
            }
        }
    }
    

    And in your storyboard or .xib. You will see

提交回复
热议问题