作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 attributePlaceholder 设置占位符和占位符颜色,如下所示:
textField.placeholder = "SOME TEXT"
textField.attributedPlaceholder = NSAttributedString(string: string ,attributes: [NSAttributedStringKey.foregroundColor: UIColor.black.cgColor])
这很好用。
但是当使用 NSLocalizedString 作为占位符时,如下所示:
注意:我已经创建了 Localized.string 文件
textField.placeholder = NSLocalizedString("textKey", comment: "Some comment")
textField.attributedPlaceholder = NSAttributedString(string: string ,attributes: [NSAttributedStringKey.foregroundColor: UIColor.black.cgColor])
这段代码总是给我一个错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType set]: unrecognized selector sent to instance 0x1c40a9300'
我做得对吗?
最佳答案
尝试这样的事情:
let string = NSLocalizedString("textKey", comment: "Some comment")
textField.attributedPlaceholder = NSAttributedString(string: string ,attributes: [NSAttributedStringKey.foregroundColor: UIColor.black])
使用常规UIColor
并仅设置为attributedPlaceholder
。
关于ios - swift 4、设置textField localizedString占位符颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49740878/
我是一名优秀的程序员,十分优秀!