iOSContainerControl resize controls inside

  1. 9 weeks ago

    Michel B

    Jun 22 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 9 weeks ago

    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 :/

    I tried to use the example of the LR at docs.xojo.com

    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)

    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 ?

  2. Dave S

    Jun 22 San Diego, California USA
    Edited 9 weeks ago

    @Michel B 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.

  3. Michel B

    Jun 22 Pre-Release Testers, Xojo Pro RubberViews.com

    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.

  4. Dave S

    Jun 22 San Diego, California USA

    yup :)

  5. 8 weeks ago

    Jeremie L

    Jun 23 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 8 weeks ago

    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:

    View.AddControl(ctrl)

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

    Something like this in a Module:

    Public Sub AddControlWithBounds(extends mView as iOSView, ctrl as iOSControl, bounds as xojo.Core.Rect)
      mView.AddControl(ctrl)
      
      Dim left As New iOSLayoutConstraint(ctrl, _
      iOSLayoutConstraint.AttributeTypes.Leading, _
      iOSLayoutConstraint.RelationTypes.Equal, _
      mView, _
      iOSLayoutConstraint.AttributeTypes.Leading, _
      1, _
      bounds.left)
      mView.AddConstraint(left)
      
      Dim top As New iOSLayoutConstraint(ctrl, _
      iOSLayoutConstraint.AttributeTypes.Top, _
      iOSLayoutConstraint.RelationTypes.Equal, _
      mView, _
      iOSLayoutConstraint.AttributeTypes.Top, _
      1, _
      bounds.top)
      mView.AddConstraint(top)
      
      Dim right As New iOSLayoutConstraint(ctrl, _
      iOSLayoutConstraint.AttributeTypes.Trailing, _
      iOSLayoutConstraint.RelationTypes.Equal, _
      mView, _
      iOSLayoutConstraint.AttributeTypes.Leading, _
      1, _
      bounds.right)
      mView.AddConstraint(right)
      
      Dim bottom As New iOSLayoutConstraint(ctrl, _
      iOSLayoutConstraint.AttributeTypes.bottom, _
      iOSLayoutConstraint.RelationTypes.Equal, _
      mView, _
      iOSLayoutConstraint.AttributeTypes.top, _
      1, _
      bounds.bottom)
      mView.AddConstraint(bottom)
    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
  6. Michel B

    Jun 23 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 8 weeks ago

    Thank you Jérémie :)

or Sign Up to reply!