Is there a way to add convenience initialisers to a custom UIView loaded from a nib?
For example this gist covers the common init method but doesn't have any convenience initializers. I have a few properties that I'd like to set in my custom UIView on initialization.
The method you want to override is awakeFromNib
(called after initialization) or viewDidLoad
(called after the view is loaded). In most cases it's easier to place initialization in viewDidLoad
. Your convenience initializers won't be called if you're loaded from a nib (initialization is done by init(coder:)
in that case).
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.