iOSContainerControl resize controls inside

I am playing with 2019R1.1 in an attempt to see if I can use Xojo instead of the iOS product created by the publisher of the Android basic I used until now.

I am trying to create a custom control by placing an iOSTextField and an iOSLine inside an iOSContainerControl. I need the controls inside to follow the width of that container on the view.

If that was in Desktop (or that other Basic I was referring to), I would simply do something like :

TextField1.Width = me.width Line1.width = me.width

Simple enough, right ? Except in Xojo iOS, for some reason (?), width is read only :confused:

I tried to use the example of the LR at

[code]Dim right As New iOSLayoutConstraint(TextField1, _
iOSLayoutConstraint.AttributeTypes.Right, _
iOSLayoutConstraint.RelationTypes.Equal, _
Self, iOSLayoutConstraint.AttributeTypes.Right, _
1.0, iOSLayoutConstraint.StandardGap, 1000)

Dim rightLine As New iOSLayoutConstraint(Line1, _
iOSLayoutConstraint.AttributeTypes.Right, _
iOSLayoutConstraint.RelationTypes.Equal, _
self, iOSLayoutConstraint.AttributeTypes.Right, _
1.0, iOSLayoutConstraint.StandardGap, 1000)[/code]

But it simply does nothing in a 1000 ms single timer when the width of the CC exists (it is zero in Open).

Why so much complexity when allowing a direct setting of Width would have done just fine ?

Because “Xojo for iOS” requires you use Autolayout, and as such the Left/Top/Width/Height are read-only (or so I have observed).
Which is rather interesting, because Apples own languages (Swift and ObjC) impose no such limitations, and allow the developer to use AL if they choose, or to not use it, and manipulate the aspects of the control frame as they see fit.

It is strange, each time I try to use Xojo for iOS, it is so alienating… As if it had been created with the idea to make things more difficult.

When I compare to XCode, or to B4i, it is so much simpler.

yup :slight_smile:

In the Xojo IDE, set the width of the Textfield to be equal to the width of the container.
Set either the left edge or horizontal center of Textfield to be equal to left edge of container, or horizontal center of container.

Do the same for the line.

When placing the container inside a view, make sure that the container constraints are correctly set to the correct size.

If you are adding the container with code, such as:


You must actually add it then set the constraints of the container control.

Something like this in a Module:

[code]Public Sub AddControlWithBounds(extends mView as iOSView, ctrl as iOSControl, bounds as xojo.Core.Rect)

Dim left As New iOSLayoutConstraint(ctrl, _
iOSLayoutConstraint.AttributeTypes.Leading, _
iOSLayoutConstraint.RelationTypes.Equal, _
mView, _
iOSLayoutConstraint.AttributeTypes.Leading, _
1, _

Dim top As New iOSLayoutConstraint(ctrl, _
iOSLayoutConstraint.AttributeTypes.Top, _
iOSLayoutConstraint.RelationTypes.Equal, _
mView, _
iOSLayoutConstraint.AttributeTypes.Top, _
1, _

Dim right As New iOSLayoutConstraint(ctrl, _
iOSLayoutConstraint.AttributeTypes.Trailing, _
iOSLayoutConstraint.RelationTypes.Equal, _
mView, _
iOSLayoutConstraint.AttributeTypes.Leading, _
1, _

Dim bottom As New iOSLayoutConstraint(ctrl, _
iOSLayoutConstraint.AttributeTypes.bottom, _
iOSLayoutConstraint.RelationTypes.Equal, _
mView, _, _
1, _
End Sub

If at one point in the flow of the app you need to change the width/height or any other constraint, the easiest way to do it is to give the constraint a name.
You can then change the offset like this:

self.Constraint("myConstraintName").offset = 100

Thank you Jrmie :slight_smile: