hor*_*oe7 7 nsattributedstring uilabel ios swift
所以,在我的 UILabel 子类的awakeFromNib 方法中,我有:
let termsArg = "Terms & Conditions"
self.linkText = termsArg
let exampleText = String(format:"By signing up you agree to our %@ and Privacy Policy", termsArg)
let underlinedAttributedString = NSMutableAttributedString(string: exampleText)
self.linkTextRange = (exampleText as NSString).range(of: termsArg)
let attributes = [NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle]
underlinedAttributedString.addAttributes(attributes, range: self.linkTextRange)
self.attributedText = underlinedAttributedString
Run Code Online (Sandbox Code Playgroud)
但是,我添加这些属性的行最终导致了严重崩溃,其中只有以下内容被吐出到控制台:
-[_SwiftValue _getValue:forType:]: 无法识别的选择器发送到实例 0x60c00005e510
我想知道出了什么问题,因为看起来我做对了一切。