m.y m.y - 2 months ago 10x
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.



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