iOS Question Center aligning custom labels with significant trailing blanks - non-breaking blanks?

JackKirk

Well-Known Member
Licensed User
Longtime User
I need to center align a custom label that has trailing blank(s), the trailing blank(s) being significant.

Googling, it would appear that I should substitute blanks for non-breaking blanks.

I believe a non-breaking blank is Chr(160).

Substituting blanks for Chr(160) has no effect - trailing blanks still ignored.

Any suggestions appreciated...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2017-05-15_07.52.35.png


B4X:
Dim s As String = "  test"
Dim cs As CSBuilder
Label1.AttributedText = cs.Initialize.Color(Colors.Transparent).Append("|").Pop.Append(s)
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel, I should have been a bit more explicit - I'm after a button with a centered label with trailing significant blanks.

Custom labels in buttons seem to require that the text is added through the button's Text property not CustomLabel.Text or CustomLabel.AttributedText

I have tried the following using CSBuilder but get a blank button:
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
  
    Private cs As CSBuilder
    Private wrk_button As Button
          
    wrk_button.InitializeCustom("", Colors.Red, Colors.Red)
    Page1.RootPanel.AddView(wrk_button, 5%x, 5%y, 90%x, 20%y)
    wrk_button.Color = Colors.Gray
    wrk_button.CustomLabel.AttributedText = cs.Initialize.Color(Colors.Red).Append("        Garbage        ").PopAll
    wrk_button.CustomLabel.Left = 5%x
    wrk_button.CustomLabel.Width = 80%x
    wrk_button.CustomLabel.Color = Colors.Transparent
    wrk_button.CustomLabel.TextAlignment = wrk_button.CustomLabel.ALIGNMENT_CENTER
    wrk_button.CustomLabel.Multiline = False
    wrk_button.CustomLabel.Font = Font.CreateNewBold(5%y)

End Sub
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
OK, got it working, seems pretty messy though...
 
Upvote 0
Top