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)
我想把依赖后的Add添加为超链接。它在所有设备上工作,除非我们更改语言时此行会导致崩溃。
当我改变iphone语言这一行导致崩溃?
languageChange: - 英语 - >印地语
崩溃:
因未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray objectAtIndex:effectiveRange :: out of bounds'
AppMessage.emptyWidget是一个本地化的字符串,但密钥在localised.string中没有相应的值,这就是为什么范围问题存在。添加了key和app的值可以正常工作。