ClassyKit / Classy

Expressive, flexible, and powerful stylesheets for UIView and friends.
http://classykit.github.io/Classy/
MIT License
740 stars 77 forks source link

UITextField Placeholder #95

Open tobinharris opened 9 years ago

tobinharris commented 9 years ago

Anyone got an example of styling a UITextField with custom colours for placeholder and input text.

image

Is achieved by this, but after editing the green text style reverts to that of the placeholder.

MyView {
  ^UILabel{
    font: $default-font 18
    text-color: #222222
  }
  UITextField{
    font: $default-font 20
    text-color: #67AB1C

    UIFieldEditor{
        UITexiFieldLabel{
        text-color: #CCCCCC
    }
      }
      UILabel{
        text-color: #67AB1C
      }

  }
} 
keithnorm commented 9 years ago

The main problem is that UIKit doesn't expose a color property for the placeholder text (see http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color). You can however set an attributed string through textField.attributedPlaceholder and set the foregroundColor of that attributed string from a property that is set via Classy.

Let me know if that doesn't make sense and I can work up a quick example.

dnedrow commented 6 years ago

@keithnorm , I don't know if you're still monitoring Classy, but could you provide the example you mentioned for using attributedPlaceholder? I've been trying to work this out and haven't found the magic combination yet.