Cue*_*Cue 2 macos nsattributedstring swift nsattributedstringkey
在使用Swift 3.2的macOS项目中,我正在尝试设置UITextView的前景色.
let placeHolderTitleString: NSAttributedString = NSAttributedString(string: "Enter text here", attributes: [NSAttributedStringKey.foregroundColor : NSColor.gray]) // error
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
类型'NSAttributedStringKey'(又名'NSString')没有成员'foregroundColor'
相同的代码在Swift 4.0项目中工作正常.
我试图根据我发现的iOS Swift 4转换错误的一些答案修改代码- NSAttributedStringKey:任何但我继续得到错误.有没有办法解决这个问题,而无需将项目更新到Swift 4?
Swift 3不使用新的Swift 4 NSAttributeStringKey值.
使用NSForegroundColorAttributeName的前景色:
let placeHolderTitleString: NSAttributedString =
NSAttributedString(string: "Enter text here", attributes:
[NSForegroundColorAttributeName : NSColor.gray])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
744 次 |
| 最近记录: |