iOS Code Snippet Resize view with parent

Similar threads

B4i Code Snippet Make Blur Any View
B4i Code Snippet Full screen apps
B4i Question NativeObject
Games [XUI2D] To Collide or Not To Collide
B4i Tutorial Multiple Pages Example


Licensed User
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: