iOS Code Snippet Resize view with parent

SubName: autoresizingMask

Ios doesn't have the FillParent option that Android does, instead it has a more flexible approach using a mask:
Documentation is here:

The mask is a series of bits that defines how a subviews size should be adjusted when the parent size changes.

Possible options are:

UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5

We can access this using NativeObject:

Dim INO As NativeObject = Img

Where 16 is equivelent to 1<<4 (Bit.ShiftLeft(1,4))

The code above will change the height of the view when the parents height changes. The change is relative, so if the view is set at 50% of the parents height, it will remain so.

To change height and width the code would be:

Dim INO As NativeObject = Img

This function is contained in the UIView class so should work on any View.

Tags: FillParent, Resize View
Last edited: