I am writing a control that has a toggle on (show/hide password). The UITextfield
has a UIImageView
in that acts as the toggle.
The question is, is it better to create the state images once and store them in the control, or to create them on demand?
Essentially this:
if let imageView = imgToggle {
if self.isSecureTextEntry {
imageView.image = UIImage(named: "eye.png")
} else {
imageView.image = UIImage(named: "no_eye.png")
}
}
vs this:
private var showPassword: UIImage? = UIImage(named: "eye.png")
private var hidePassword: UIImage? = UIImage(named: "no_eye.png")
///...
if let imageView = imgToggle {
if self.isSecureTextEntry {
imageView.image = showPassword
} else {
imageView.image = hidePassword
}
}
Is there any overhead in constantly recreating the image? How does that compare to storing the image in the control?