The reason it doesn't work in ViewDidLoad
is that all the sizes are not yet final there, in fact, Im betting it would also not work in viewWillAppear
.Im guessing you are not liking making the change in viewDidAppear
as it is visible to the user. The correct place to set the size is viewWillLayoutSubviews
.
The flow is
viewDidLoad
viewWillAppear
viewDidLayoutSubviews
viewDidApear
I suggest you reread those methods in the documentation.