(Lots of preamble here, but the question at the bottom is: "Can anyone offer insights as to how to have a canvas control within a custom table cell dynamically control the height of the cell?” There are actually two questions in here; I’ve marked them in bold.)
I’ve created an iOS control to replace the Label control because I need to control the text line height:
It’s working fine, but I’m having trouble using it on iOS. The MobileCanvas needs to recalculate it’s height. I can’t seem to find a way to get a control’s constraints—I’d like to read the control’s height constraint(s) and replace them as needed. Not having a height constraint doesn’t work—the control is never drawn. As a workaround, I have set a height contraint in the IDE with a minimum height:
That’s working fine, but now I’m in trouble because I want to use this control in a MobileTableCustomCell with dynamic height. If I were to use a native MobileLabel control and set it with different lines of text, it dynamically recomputes the height of the MobileTableCustomCell:
But I’m not using MobileLabel because the line height in multiline text is too tight—it needs more spacing. But when I use my custom canvas, I’m not quite understanding how to set up the constraints to dynamically:
FWIW, this the code to dynamically change the height in my canvas is in the paint event. (Obviously it may have to be drawn twice, once with the initial height, then with the correct, final height.)
If Me.TextHeight <> Me.Height Then
If Me.HeightConstraint <> Nil Then
Me.RemoveConstraint(Me.HeightConstraint)
End
// Adjust height
Me.HeightConstraint = New iOSLayoutConstraint( _
Me, _
iOSLayoutConstraint.AttributeTypes.Height, _
iOSLayoutConstraint.RelationTypes.GreaterThanOrEqual, _
Nil, iOSLayoutConstraint.AttributeTypes.None, _
1, _
Me.TextHeight)
Me.AddConstraint(Me.HeightConstraint)
Declare Sub setNeedsLayout Lib "UIKit.framework" Selector "setNeedsLayout" (obj_id As ptr)
setNeedsLayout(Self.Handle)
End
Can anyone offer insights as to how to have a control within a custom table cell control the height of the cell?