简体   繁体   中英

Convenience initializers for custom uiview loaded from .xib

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.

https://gist.github.com/bwhiteley/049e4bede49e71a6d2e2

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM