xcode/iOS: Autoresize to fill a view - explicit frame size is essential? xcode/iOS: Autoresize to fill a view - explicit frame size is essential? ios ios

xcode/iOS: Autoresize to fill a view - explicit frame size is essential?


Autoresizing does not mean that the subview will take up the size of its superview. It just means that it will resize relative to the size change of its superview whenever the superview's bounds change. So initially, you have to set the size of the subview to the correct value. The autoresizing mask will then deal with size changes in the future.

This is all you need:

textView = [[[UITextView alloc] autorelease] initWithFrame:self.view.bounds];[textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|                              UIViewAutoresizingFlexibleHeight];


And here Swift 3 solution:

myView.autoresizingMask = [.flexibleWidth, .flexibleHeight]