How to Use Autoresize for a View in iOS Programmatically

1.8k views Asked by At

I've used Auto resize in Interface Builder and It's Works fine. But I want to know how to do that in programmatically. Because i want to change AutoResizing mask in ViewDidload according iPhone Series.

The Code I've used is given below:

_moreOptionsView.autoresizingMask = (UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin);

I want to set Auto Resizing Mask to Width, Height, Right Margin & Top Margin through Programmatically.

2

There are 2 answers

1
Woodstock On

You simple have to set the Autoresizing Mask of the view in question like so:

myView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;

This is achieved using the Bitwise OR operator. It will set all bits true that are true in either of both values provided.

0
Sandeep Agrawal On