How to set iOS UITextField placeholder color? (RubyMotion + iOS)

可紊 提交于 2019-12-11 06:04:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!