问题
How to use RubyMotion to set a textField's placeholder text foreground color?
Example code:
textField = UITextField.alloc.init
textField.placeholder = "Hello World"
The placeholder text shows up gray; I want it to be red.
This is using RubyMotion, not Objective-C.
回答1:
Use an attributed string like this:
self.attributedPlaceholder =
NSAttributedString.alloc.initWithString(
self.placeholder || "Hello World",
attributes: {NSForegroundColorAttributeName => UIColor.redColor}
)
This works on iOS7, and likely on iOS6, and not on earlier iOS versions.
Careful: be certain to use the hash syntax key => val
instead of key: val
.
来源:https://stackoverflow.com/questions/25236456/how-to-set-ios-uitextfield-placeholder-color-rubymotion-ios