具有链接属性的NSMutableAttributedString问题

时间:2019-05-30 07:24:38

标签: ios swift nsmutableattributedstring

我在Swift 5,iOS 12.1中运行以下代码:

let linkText = NSMutableAttributedString(string: "this is link", attributes: [.link: NSString(string: "http://example.com")])
textView.attributedText = linkText
textView.linkTextAttributes = [.foregroundColor: UIColor.blue, .underlineColor: UIColor.blue, .underlineStyle: NSUnderlineStyle.single]

我收到错误消息:

[__SwiftValue integerValue]: unrecognized selector sent to instance 0x600002ba3b10

我不知道怎么了。

1 个答案:

答案 0 :(得分:0)

使用此NSUnderlineStyle.single.rawValue

代替NSUnderlineStyle.single

textView?.linkTextAttributes = [.foregroundColor: UIColor.blue, .underlineColor: UIColor.blue, .underlineStyle: NSUnderlineStyle.single.rawValue]