Sunday, 25 September 2011

Autoresizing Masks in the Cocoa Framework

I've been struggling a bit to get my head around exactly how the different UIViewAutoresizing values work together. This post is an examination of trying out various combinations and documenting the effects.

The first thing to do is set up two views, one within the other. Then, the autoresizingMask of the inner view is set and the frame of the outer view changed.

This is what the two views look like before any resizing:


Below are the results of changing the size of the outer view's frame, using various values for the inner view's autoresizingMask property.

UIViewAutoresizingNone:
This causes the inner view's frame to remain unchanged.


UIViewAutoresizingFlexibleTopMargin:
This causes only the y coordinate of the inner view's frame to change.


UIViewAutoresizingFlexibleBottomMargin:
This causes the inner view's frame to remain unchanged.


UIViewAutoresizingFlexibleLeftMargin:
This causes only the x coordinate of the inner view's frame to change.


UIViewAutoresizingFlexibleRightMargin:
This causes the inner view's frame to remain unchanged.


UIViewAutoresizingFlexibleWidth:
This causes only the width of the inner view's frame to change.


UIViewAutoresizingFlexibleHeight:
This causes only the height of the inner view's frame to change.


UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight:
This causes the y coordinate and height of the inner view's frame to change.


UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth:
This causes the x coordinate and width of the inner view's frame to change.

No comments:

Post a Comment