SubName: SetTextSize
Description: Sets the text size for a given text to fill in a given Label or EditText view.
Tags: Label, TextSize, EditText, text size
Dependencies: StringUtils library
Usage for the image below:
Original post.
Description: Sets the text size for a given text to fill in a given Label or EditText view.
B4X:
Sub Globals
Dim stu As StringUtils
End Sub
Sub SetTextSize(lbl As Label, txt As String)
Dim dt As Float
Dim limit = 0.5 As Float
Dim h As Int
lbl.Text = txt
lbl.TextSize = 72
dt = lbl.TextSize
h = stu.MeasureMultilineTextHeight(lbl, txt)
Do While dt > limit OR h > lbl.Height
dt = dt / 2
h = stu.MeasureMultilineTextHeight(lbl, txt)
If h > lbl.Height Then
lbl.TextSize = lbl.TextSize - dt
Else
lbl.TextSize = lbl.TextSize + dt
End If
Loop
End Sub
Dependencies: StringUtils library
Usage for the image below:
B4X:
Dim txt = "This is the time for all good men to come to the aid of their country" As String
SetTextSize(Label1, txt)
SetTextSize(Label2, txt)
SetTextSize(Label3, txt)
Original post.
Attachments
Last edited: