iOS Question Text alignment for label

Nitin Joshi

Active Member
Licensed User
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.
 

Attachments

  • Label alignment.png
    Label alignment.png
    17.8 KB · Views: 16
Solution
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.
1743002310541.png


The solution is simply this:
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    Label1.As(Label).SizeToFit
End Sub

Alexander Stolte

Expert
Licensed User
Longtime User
vertical has no effect
This is the native behaivor of the ios label.
1742923185956.png

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.
 
Upvote 1

Nitin Joshi

Active Member
Licensed User
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.
this has not worked...

Label Code:
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
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
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.
1743002310541.png


The solution is simply this:
B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    Label1.As(Label).SizeToFit
End Sub
 
Upvote 0
Solution

Nitin Joshi

Active Member
Licensed User
@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.

Please suggest what can be done.
 

Attachments

  • Project.zip
    182 KB · Views: 20
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
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
 
Upvote 0
Top