Reputation: 815
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)
i want to make Add which is after please as hyperlink . Its working in all devices except when we change the language this line causes crash .
when i changed language of iphone this line causing crash ?
languageChange :- English -> Hindi
crash :
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
Upvotes: 0
Views: 127
Reputation: 815
AppMessage.emptyWidget was a localised string but the key was not having corresponding value in localised.string thats why range issue was there . Added the value of key and app works fine.
Upvotes: 0