How to programmatically create UIView with this setup?

anna picture anna · Feb 12, 2012 · Viewed 14.3k times · Source

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

Answer

Thomás Pereira picture Thomás Pereira · Sep 18, 2015

Swift 2.0:

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

Swift 3.0:

view.autoresizingMask = [.flexibleHeight, .flexibleWidth]