nghialv / MaterialKit

Material design components for iOS written in Swift
MIT License
2.5k stars 290 forks source link

MKTextField attributed placeholder support #7

Open siggb opened 9 years ago

siggb commented 9 years ago

Here code for attributed placeholder support:

override var attributedPlaceholder: NSAttributedString! {
        didSet {
            floatingLabel.text = attributedPlaceholder.string
            floatingLabel.sizeToFit()
            setFloatingLabelOverlapTextField()
        }
    }

I also wrote wrapped method for setting attributed placeholder:

func setAttributedPlaceholder(text : NSString) {
        var attrs = [NSFontAttributeName : self.font, NSForegroundColorAttributeName : UIColor.grayColor()]
        var str = NSAttributedString(string: text, attributes: attrs)

        self.attributedPlaceholder = str
    }