gpt4 book ai didi

ios - swift 4、设置textField localizedString占位符颜色

转载 作者:行者123 更新时间:2023-11-30 11:36:13 24 4
gpt4 key购买 nike

使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com