I have a container with an imagewell and a Textarea. When I add it to the scrollable area the imagewell and textarea stretch beyond the device width.
How do you restrict the container to the device bounds?
You need to manually add a width layout constraint by code.
Canât seem to get this correct.
So if I want to set the constraint of the imagewell in the container to the scrollable area width and if I use the following to define the right of the imagewell. What would the syntax be? Iâve looked but canât see an example I can adapt
Dim right As New iOSLayoutConstraint(me, _
iOSLayoutConstraint.AttributeTypes.Right, _
iOSLayoutConstraint.RelationTypes.Equal, _
Self, iOSLayoutConstraint.AttributeTypes.Right, _
1.0, iOSLayoutConstraint.StandardGap)
On the container layout editor make sure the imagewell is constrained to the containerâs width.
When adding the container to the scrollable area, define a width layout constraint for the container, relative to the scrollable area.
Constraints must be defined from child to direct parent element. Never to n-th parent element.
Still not getting it, I tried the following in the open event of the scrollablearea but still the same
Dim c As iOSLayoutConstraint = Self.Constraint(âScrollwidthâ)
c.Offset = self.ScrollableArea1.Width
I think you donât fully understand how layout constraints work.
This might help:
http://documentation.xojo.com/topics/user_interface/ios/creating_screens_that_auto-resize_using_auto_layout.html
Iâve done this successfully with an iOSCustomTableCell to adjust the height of the cell, using the technique in the example project included with Xojo (canât remember the name of the example project).
The label I add the height constraint to doesnât have the height defined as a constraint in the IDE. Otherwise youâd have 2 conflicting constraints. Maybe thatâs the problem.
Am I suppose to set the Scrollablearea content to my container?
I still canât reference the controls from the scrollablearea open event to set a constraint
I had success doing that also making some customtablecells variations for iPhone vs iPad which worked well but Iâm just not getting it. Iâll just keep trying to adapt the examples
Hi Martin, is this the same problem?
Tried cleaning that up but what is the âcontentâ
Dim cons as iOSLayoutConstraint
cons = new iOSLayoutConstraint(content, _
iOSLayoutConstraint.AttributeTypes.Width, _
iOSLayoutConstraint.RelationTypes.Equal, _
ScrollableArea1, _
iOSLayoutConstraint.AttributeTypes.Width, _
1.0, 0)
cons.Active = True
ScrollableArea1.AddConstraint(cons)
Probably scollablearea.content itâs a property
Genius
Thanks Christoph, it makes sense now I see it but I wouldnât have got the connection without
Not quite there. The textfield and text area are now bound to the width of the scrollarea but I am still having trouble with the Imagewell, most likely because I have defined its height as 35% of the parent screen height which worked fine b4 I made it scrollable. How can I define the height of the imagewell that is in the container to be 35% of the device height?
Can you define it as 35% of the scrollable area? Might be a solid workaround if the scrollable area has the same height as the device.
I tried the following but the second constraint didnât work. How would I address just the Imagewell which is control(1)?
Dim c2 As new LargeContainer
c2.Setdata
me.AddControl(c2)Dim cons as iOSLayoutConstraint
cons = new iOSLayoutConstraint(ScrollableArea1.content, _
iOSLayoutConstraint.AttributeTypes.Width, _
iOSLayoutConstraint.RelationTypes.Equal, _
ScrollableArea1, _
iOSLayoutConstraint.AttributeTypes.Width, _
1.0, 0)
cons.Active = True
ScrollableArea1.AddConstraint(cons)Dim cons2 as iOSLayoutConstraint
cons2 = new iOSLayoutConstraint(c2.Control(1), _
iOSLayoutConstraint.AttributeTypes.height, _
iOSLayoutConstraint.RelationTypes.Equal, _
ScrollableArea1, _
iOSLayoutConstraint.AttributeTypes.height, _
0.4, 0)
cons2.Active = True
ScrollableArea1.AddConstraint(cons2)
I am not sure but I believe the last command is wrong. You should add the constraint cons2 to c2 instead of ScrollableArea1.
No that canât work as c2 is a container not a constraint
Actually thatâs correct @Christoph_Emrich Ahh I left some test data in the container controls so I wasnât seeing the instance created which was masking to some extent the constraint effect
Dim c2 As new LargeContainer
//set the data for the container
c2.ImageView1.Image = Unknown
c2.TextArea1.text = InfoText
//add the container
me.AddControl(c2)//Set the constraint to tie the container to the scrollablearea width
Dim cons as iOSLayoutConstraint
cons = new iOSLayoutConstraint(c2.Control(1), _
iOSLayoutConstraint.AttributeTypes.Width, _
iOSLayoutConstraint.RelationTypes.Equal, _
ScrollableArea1, _
iOSLayoutConstraint.AttributeTypes.Width, _
1.0, 0)ScrollableArea1.AddConstraint(cons)
cons.Active = True