NSAttributedString.draw非常慢

时间:2018-04-19 14:50:05

标签: ios swift

let stopwatch = Stopwatch.createStarted()

if text.length != 0 {
    text.draw(with: textRect, options: .usesLineFragmentOrigin, context: nil)
}

print("stopwatch \(stopwatch.stop().toString())")

结果:

stopwatch 0.0241029262542725 s
stopwatch 0.0221379995346069 s
stopwatch 0.00433492660522461 s
stopwatch 0.00229907035827637 s
stopwatch 0.00661897659301758 s
stopwatch 0.00540506839752197 s
stopwatch 0.0047069787979126 s
stopwatch 0.00523698329925537 s
stopwatch 0.0541820526123047 s

text.draw需要50毫秒。 有没有办法优化NSAttributedString.draw的性能?

这是NSAttributedString

的示例

enter image description here

0 个答案:

没有答案