How to achieve that placeholder text disappears character by character in UITextField

后端 未结 6 1853
挽巷
挽巷 2021-02-18 20:28

Can you please help me.

In UITextField when we provide a placeholder text its placeholder string will be gone when we enter any character. How can I achieve

6条回答
  •  长情又很酷
    2021-02-18 21:14

    For that situation use attributed string in swift like bellow,

    let attributeFontSaySomething : [String : Any] = [NSFontAttributeName : UIFont.systemFont(ofSize: 12.0)]
    let attributeColorSaySomething : [String : Any] = [NSForegroundColorAttributeName : UIColor.blue]
    
    var attributes = attributeFontSaySomething
    for (key, value) in attributeColorSaySomething {
        attributes(value, forKey: key)
    }
    
    let attStringSaySomething = NSAttributedString(string: "Say something", attributes: attributes)
    

提交回复
热议问题