Hiren Hiren - 1 year ago 190
iOS Question

Set UIView's autoresizing mask programmatically?

I have to set autoresizingMask programmatically for


I don't know how to implement this.

enter image description here

Answer Source

To achieve what you have in that screen shot you need to do the opposite of what DrummerB suggests. You want a fixed top margin so you make every other side flexible like so:

view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
                        UIViewAutoresizingFlexibleLeftMargin |

Not setting a side as flexible means that it will be fixed (default behaviour), thats why there is no such thing as UIViewAutoResizingFixedTopMargin (since its the same as not setting UIViewAutoresizingFlexibleTopMargin)

Edit for Swift:

view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download