【发布时间】:2017-11-07 13:55:25
【问题描述】:
亲爱的,
我正在快速学习,我正在尝试为文本字段文本着色,现在的问题是颜色未应用于文本。请在下面找到代码:
let textStyle:[String:Any] = [
NSAttributedStringKey.strokeColor.rawValue: UIColor.black,
NSAttributedStringKey.foregroundColor.rawValue: UIColor.white,
NSAttributedStringKey.font.rawValue: UIFont (name: "Impact", size: 50)!,
NSAttributedStringKey.strokeWidth.rawValue: 3.5
]
谢谢
【问题讨论】:
-
From apple "渲染时使用该属性指定文本的颜色。如果不指定该属性,则文本呈现黑色。"所以你在白色上设置白色没有? Foregroundcolor 似乎修改了文本颜色,我想这不是你想要做的?
-
删除
.rawValue。textStyle也应该是[NSAttributedStringKey:Any]类型而不是[String:Any] -
您是否意识到您可以简单地设置
UITextField的属性?myTextField.textColor = UIColor.black -
我尝试使用 .textColor 直接更改它及其工作,但当我添加描边颜色时却没有
标签: ios swift colors textfield swift4