【发布时间】:2018-07-23 14:01:14
【问题描述】:
我将我的代码从 Swift 3 转换为 Swift 4,但出现此错误:
类型“NSAttributedStringKey”没有成员“foregroundColorNSAttributedStringKey”
我的代码是:
let labelText = NSMutableAttributedString(string: (self.productDetailsInfo?.productAttributes?[indexPath.row].Name as String?)!)
labelText.append(NSAttributedString(string:"*"))
let selectedRange = NSMakeRange(labelText.length - 1, 1);
labelText.addAttribute(NSAttributedStringKey.foregroundColorNSAttributedStringKey.foregroundColor, value: UIColor.red, range: selectedRange)
labelText.addAttribute(NSAttributedStringKey.baselineOffset, value: 2, range: selectedRange)
【问题讨论】:
-
删除那行
labelText.addAttribute(NSAttributedStringKey.foregroundColorNSAttributedStringKey.foregroundColor, value: UIColor.red, range: selectedRange),手动重做,让自动补全帮助你。
标签: ios swift swift3 swift4 nsattributedstringkey