【发布时间】:2018-06-01 21:08:48
【问题描述】:
let initialStr = "To see information for today, please"
let tempFontSize = UIUtils.getFontForApproprieteField(.subHeadline).font.pointSize
let tealDict = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: tempFontSize), NSAttributedStringKey.foregroundColor: UIColor.LTColor()]
let linkAttributes = [NSAttributedStringKey.foregroundColor: UIColor.LTColor(), NSAttributedStringKey.underlineStyle: NSNumber(value: false as Bool)]
errorLbl?.linkAttributes = linkAttributes
errorLbl?.delegate = self
let attributedString = NSMutableAttributedString(string: AppMessage.emptyWidget, attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: tempFontSize)])
attributedString.addAttributes(tealDict, range: NSMakeRange(initialStr.length+1,3))
errorLbl?.attributedText = attributedString
let rangeT : NSRange = (AppMessage.emptyWidget as NSString).range(of: " add")
errorLbl?.addLink(to: URL(string: "https://www.google.co.in/")!, with: rangeT)
我想将 please 之后的 Add 设为超链接。它适用于所有设备,除非我们更改此行导致崩溃的语言。
当我更改 iphone 的语言时,这条线导致崩溃?
languageChange :- 英语 -> 印地语
崩溃:
由于未捕获的异常“NSRangeException”而终止应用程序,原因:“NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds”
【问题讨论】:
-
这意味着您传递的范围不正确。你需要调试它。
-
已调试。 nslocalised 字符串键没有对应的值,这就是原因。
标签: ios iphone swift localization nsmutablestring