m.y m.y - 1 year ago 127
Swift Question

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.


Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download