When does the correct frame size of the UIView is calculated when I add my custom UIView by using storyboard?
I can't get correct frame size in UIView's init(frame: CGRect)
or init(coder aDecoder: NSCoder)
or awakeFromNib()
. I get the correct size in override func layoutSubviews()
but this time the view is not added to the view controller's view.
Edit:
I want to do this in the UIView subclass because I add a CAGradientLayer
layer (which has same size with my view) to my custom UIView
. There must be a better way than setting up the view in UIViewController
s viewDidLayoutSubviews
method.
There are two vertical constraints (trailing and leading space to superview) that adjust the width of my custom view. But the width is 600 in the mentioned methods, not the screen width.
I get the correct size in override func layoutSubviews() but this time the view is not added to the view controller's view.
Why? – akashivskyy