【发布时间】:2018-06-10 14:02:08
【问题描述】:
这是我的代码: 我正在尝试格式化我的文本 NSMutableAttributedString(),但它似乎总是超出范围。
由于未捕获的异常“NSRangeException”而终止应用程序,原因:“NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds”
extension ImageTableViewCell {
func formatLabel(code: SectionItem) {
print(code.statusType.title)
let stringFormatted = NSMutableAttributedString()
let range = (code.statusType.title as NSString).range(of: code.statusType.title)
print(range); stringFormatted.addAttribute(NSAttributedStringKey.foregroundColor, value: code.statusType.color, range:range)
stringFormatted.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: range)
self.titleLabel.attributedText = stringFormatted
}
}
不知道能不能修复
我试过了:
NSRange
NSMakeRange(loc: 0, mytext.count)
请问还有什么遗漏的?
【问题讨论】:
标签: ios swift nsattributedstring