【发布时间】:2018-02-15 22:29:06
【问题描述】:
我正在尝试使用 NSAttributed 字符串在字符串下划线。出于某种原因,我的行导致了异常:
-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance
结果应该用于 UITableView 中的 UILabel 并根据需要创建。
这是代码:
attributedString = NSMutableAttributedString(string: message)
if let actor = event.actor {
let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle]
var attributedActorString = NSMutableAttributedString(string: actor.shirtName, attributes: attributes)
attributedActorString.insert(NSAttributedString(string: " "), at: 0)
attributedActorString.append(NSAttributedString(string: ". ")) attributedActorString.append(attributedImageStringForUrl(event.actor!.portraitImageUrl, indexPath: indexPath))
attributedString.append(attributedActorString)
}
【问题讨论】:
-
underlineStyle键需要一个整数值(特别是NSNumber),因此您需要使用NSUnderlineStyle的rawValue。
标签: swift swift3 nsattributedstring