Question

I'd like to create a UIView programmatically with the exact equivalent of this setup in IB (see screenshot).

Whatever I have attempted myself would not behave the same when rotating and autoresizing the view, so I need a sample from an expert.

UIView in IB

Was it helpful?

Solution

Example:

UIView *customView = [[UIView alloc] initWithFrame:frame];
[customView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];

OTHER TIPS

Swift 2.0:

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

Swift 3.0:

view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
  View.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin,.FlexibleWidth,.FlexibleHeight,.FlexibleTopMargin]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top