UITextField set placeholder color as dark in iOS

前端 未结 8 753
误落风尘
误落风尘 2021-02-01 10:59

I have tried to set UITextField \"Placeholder\" color as dark.

NSAttributedString * search = [[NSAttributedString alloc] initWithSt         


        
8条回答
  •  借酒劲吻你
    2021-02-01 11:26

    For iOS8, you can take advantage of @IBDesignable & @IBInspectable.

    Here is a UITextField subclass in Swift which lets you set the placeholder color in Interface Builder and see the result instantly:

    @IBDesignable class EDTextField: UITextField {
        @IBInspectable var placeholderColor: UIColor = UIColor.whiteColor() {
            didSet {
                if let placeholder = self.placeholder {
                    let attributes = [NSForegroundColorAttributeName: placeholderColor]
                    attributedPlaceholder = NSAttributedString(string: placeholder, attributes: attributes)
                }
            }
        }
    }
    

提交回复
热议问题