0
for i in 0...attString.length-1
{
attString.enumerateAttribute(NSBackgroundColorAttributeName, in: NSMakeRange(i,1), options: NSAttributedString.EnumerationOptions(rawValue: 0)) { (value, range, stop) -> Void in
if let exValue = value as? UIColor
{
if self.compareColors(c1: exValue, c2: (UIColor(hex: 0x2e4270))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xc0e1ff))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0x7a99b8))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xaad5fb)))
{
aRange = NSMakeRange(i, 1)
myValue = self.styles.blueHighlightColor()
//DispatchQueue.main.async {
mutableAttString.addAttribute(attributeName, value: myValue, range: aRange)
//}
self.saveChanges = true
}
else if self.compareColors(c1: exValue, c2: (UIColor(hex: 0x385324))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xbde970))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0x88a752)))
{
aRange = NSMakeRange(i, 1)
myValue = self.styles.greenHighlightColor()
//DispatchQueue.main.async {
mutableAttString.addAttribute(attributeName, value: myValue, range: aRange)
// }
self.saveChanges = true
}
else if self.compareColors(c1: exValue, c2: (UIColor(hex: 0x624b85))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xd6affb))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0x997eb8))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xd6affb)))
{
aRange = NSMakeRange(i, 1)
myValue = self.styles.pinkHighlightColor()
// DispatchQueue.main.async {
mutableAttString.addAttribute(attributeName, value: myValue, range: aRange)
//}
self.saveChanges = true
}
else if self.compareColors(c1: exValue, c2: (UIColor(hex: 0x7b5b15))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xfbe769))) ||
self.compareColors(c1: exValue, c2: (UIColor(hex: 0xb4a64d)))
{
aRange = NSMakeRange(i, 1)
myValue = self.styles.yellowHighlightColor()
// DispatchQueue.main.async {
mutableAttString.addAttribute(attributeName, value: myValue, range: aRange)
//}
self.saveChanges = true
}
}
}
} // For loop end
모든 NSAttributed 문자를 반복하고 배경색을 확인하고 있습니다. 그것이 분명하다면, 또는 if 문에 정의되지 않은 다른 색상. 그것은 잘 작동하지만 큰 텍스트를 입력하면 다소 느립니다. 나는 DispatchQueue.concurrentPerform(iterations:execute:)
을 사용해 보았습니다.하지만 충돌합니다. 이유가 없습니다.루프를위한 그랜드 센터 파견
고마워! 지금은 매우 빠릅니다. 어떻게 할 수 있는지 보여줄 수 있습니까? – Elita