I have a custom text view with round corner radius. After testing in instrument, I am finding that it takes 53ms to initialize it (or is it?). I thought 53ms is bit much for one UI component so I was wondering if there is a faster way of doing it? Below are my instrument output and customTextView code.
import UIKit
class CustomTextView: UITextView {
private func initialize() {
self.layer.borderColor = UIColor(red: 225.0/255, green: 225.0/255, blue: 225.0/255, alpha: 1).CGColor
self.layer.borderWidth = 1.0
self.layer.cornerRadius = 5
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
}
I do some investigation about that :
Initial time is 83 millisecond.
Firstly if we do some calculation for layer it will save you 1 millisecond so it is 82 millisecond.
private func initialize() {
self.layer.borderColor = UIColor(red: 0.88, green: 0.88, blue: 0.88, alpha: 1).CGColor
self.layer.borderWidth = 1.0
self.layer.cornerRadius = 5
}
After disabling of the initialize()
method it is 75 millisecond.
So let just test regular UITextView
and we see that it is 82 seconds
Conclusion it is normal init time for UI element.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.