I want to apply text alignment vertical to label however for B4i text alignment for vertical has no effect. Is there any work around as i want content of the label should be appear from top.
If the “Handle Resize Event” checkbox is checked on a layout, the views on this form are automatically resized according to its anchor points. This means that if you want to change the size of a label manually, you have to do this in the Base_Resize event, as this is the only way to counteract this.
The solution is simply this:
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
Label1.As(Label).SizeToFit
End Sub
This is the native behaivor of the ios label.
use the xlbl.As(Label).SizeToFit to adjust the size of the label to the text, then the text is also displayed at the top.
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Label1 As B4XView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Label1.As(Label).SizeToFit
End Sub
If the “Handle Resize Event” checkbox is checked on a layout, the views on this form are automatically resized according to its anchor points. This means that if you want to change the size of a label manually, you have to do this in the Base_Resize event, as this is the only way to counteract this.
The solution is simply this:
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
Label1.As(Label).SizeToFit
End Sub
@Alexander Stolte I have one finding. If we keep label content blank in design view then unless and until screen orientation is not changed label will not show any content.
I have uploaded project once again. Please follow these steps to understand my point...
1) Click button so that label text will be updated
2) Label contain will be nil
3) move the screen (let resize event occur) then label will show the content.
The B4XPage_Resize event is not triggered again just because your label has now been given a new text.
You have to call the sizetofit again after setting the text.
B4X:
Private Sub B4XPage_Resize(Width As Float, Height As Float)
Label1.As(Label).SizeToFit
End Sub
Private Sub Button1_Click
Label1.Text="This is the first line of label" & CRLF & "This is the second line of label"
Label1.As(Label).SizeToFit
End Sub