NSAttributedStringKey giving an unresolved identifier error

后端 未结 6 1790
暖寄归人
暖寄归人 2020-12-30 04:15

I\'m following an online tutorial to build a magazine type iOS application. I\'m attempting to use NSAttributedStringKey but keep getting the error shown below. Any ideas?

6条回答
  •  爱一瞬间的悲伤
    2020-12-30 04:40

    Swift 4.1 and Xcode 9.3 changes Attributed key value.

    let strName = "Hello Stackoverflow"
    let string_to_color2 = "Hello"        
    let attributedString1 = NSMutableAttributedString(string:strName)
    let range2 = (strName as NSString).range(of: string_to_color2)       
    attributedString1.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.red , range: range2)
    lblTest.attributedText = attributedString1
    

    Hello will be in red color.

提交回复
热议问题