Ich versuche, den arabischen Text zu markieren, aber es funktioniert nicht, schließlich das Programm abgestürzt ist mit Fehler:Highlight arabischer Text mit Timer
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
mein Code:
super.viewDidLoad()
myMutableString = NSMutableAttributedString(string: longString)
var currentLocation = 0
var currentLength = 0
var char = CharacterSet.whitespaces
let arrayOfWords = longString.components(separatedBy: char)
for word in arrayOfWords
{
currentLength = word.characters.count
ranges.append(NSRange(location: currentLocation, length: currentLocation+currentLength))
currentLocation += currentLength + 1
}
let mySelector = #selector(self.keepHighlighting)
let timer = Timer.scheduledTimer(timeInterval:0.5, target: self, selector: mySelector, userInfo: tempLbl , repeats: true)
timer.fire()
}
und Highlight Teil ist:
func keepHighlighting(timer:Timer)
{
let lbl = timer.userInfo as! UILabel
myMutableString.addAttribute(NSFontAttributeName, value: UIFont(name: "Al_Mushaf", size: 40.0)!, range:ranges[wordNum])
myMutableString.addAttribute(NSForegroundColorAttributeName,value: UIColor.blue,range: ranges[wordNum])
lbl.attributedText = myMutableString
wordNum = wordNum + 1
}
Dieser Code funktioniert, aber ihre Indexbereich verpassen zuletzt abgestimmt ...
seine Arbeit.Vielen Dank –