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

stevel05

Expert
Licensed User
SubName: autoresizingMask

Description:
Ios doesn't have the FillParent option that Android does, instead it has a more flexible approach using a mask:
Documentation is here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/index.html#//apple_ref/occ/instp/UIView/autoresizingMask

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:

B4X:
Dim INO As NativeObject = Img
INO.SetField("autoresizingMask",16)
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:

B4X:
Dim INO As NativeObject = Img
INO.SetField("autoresizingMask",18)
This function is contained in the UIView class so should work on any View.

Tags: FillParent, Resize View
 
Last edited:
Top