Reputation: 3581
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()
}
}
Upvotes: 1
Views: 125
Reputation: 15512
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.
Upvotes: 1