如何设置iOS UITextField占位符颜色? (RubyMotion + iOS) [英] How to set iOS UITextField placeholder color? (RubyMotion + iOS)

查看:109
本文介绍了如何设置iOS UITextField占位符颜色? (RubyMotion + iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用RubyMotion设置textField的占位符文本前景颜色?

How to use RubyMotion to set a textField's placeholder text foreground color?

示例代码:

textField = UITextField.alloc.init
textField.placeholder = "Hello World"

占位符文本显示为灰色;我想要它是红色的。

The placeholder text shows up gray; I want it to be red.

这是使用RubyMotion,而不是Objective-C。

This is using RubyMotion, not Objective-C.

推荐答案

使用如下属性字符串:

self.attributedPlaceholder = 
  NSAttributedString.alloc.initWithString(
    self.placeholder || "Hello World",  
    attributes: {NSForegroundColorAttributeName => UIColor.redColor}
  )

这适用于iOS7,可能在iOS6上,而不是早期的iOS版本。

This works on iOS7, and likely on iOS6, and not on earlier iOS versions.

一定要使用哈希语法 key => val 而不是键:val

Careful: be certain to use the hash syntax key => val instead of key: val.

这篇关于如何设置iOS UITextField占位符颜色? (RubyMotion + iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆