iOS Question bt.CustomLabel.ALIGNMENT_LEFT does not work

Giusy

Active Member
Licensed User
Hi,
I create buttons programmatically but the instruction
bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
does not work, the alignement is always in center.
Also with ALIGNMENT_RIGHT the alignement is Center

which is the problem?

Thanks
 
Show all the code, there will be some error or next code that restores the original state to the center.

(PS I told you there was something to cry about)
 
Upvote 0
I'm afraid that you cannot set the text alignment in a button.
The internal Label dimensions are adapted to the text size.
If you Log the Left and Width properties you get 0.
I made several tests, below the test code:
Code: Copy
    For y = 0 To rows-1
        Dim bt As Button
'        bt.Initialize("Button",bt.STYLE_SYSTEM)
'        bt.InitializeCustom("Button", Colors.RGB(0, 0, 128), Colors.Blue)
        bt.InitializeCustom("Button", Colors.White, Colors.Green)
        strlines =list1.get(y)
        bt.Text = strlines
        bt.Tag = y * columns
        bt.Color = Colors.Red
        bt.SetBorder(2dip, Colors.Blue, 10dip)
        bt.CustomLabel.Color = Colors.Blue
        bt.CustomLabel.Left = 0
'        Log(bt.CustomLabel.Left)
'        Log(bt.CustomLabel.Width)
        bt.CustomLabel.Width = bwidth
        bt.CustomLabel.AdjustFontSizeToFit = False
'        bt.CustomLabel.Font = Font.CreateNewBold(20)
        If y Mod 2 = 0 Then
            bt.CustomLabel.Font = Font.CreateNew(20)
        Else
            bt.CustomLabel.Font = Font.CreateNew(15)
        End If
        bt.CustomLabel.SetBorder(2dip, Colors.Yellow, 5dip)
        bt.CustomLabel.Multiline = False
        bt.CustomLabel.TextColor = Colors.RGB(0, 0, 128)
        bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
        screenscrollview.Panel.AddView(bt, 2dip, y * BHeight + 2dip, bwidth, BHeight-4dip)  'Add Button
    Next
There is maybe a possibility with NativeObject, but don't have enough experience.
 
Last edited:
Upvote 0
Hi @klaus
Thank you for the hard work you did, but always centered :(
It is incredible that such a simple instruction becomes so difficult
It' a bug!
 

Attachments

  • ALIGNEMENT.jpg
    ALIGNEMENT.jpg
    68.1 KB · Views: 517
Upvote 0
After creating your button(s), add

Code: Copy
    Dim bno As NativeObject = myButton
    Dim myAlignment as int = 1       ' 0:Center    1:Left     2:Right
    bno.SetField("contentHorizontalAlignment", myAlignment)
 
Upvote 0
I noticed that the values that are assigned to TextAlignment are different:
Code: Copy
 Lbl.TextAlignment=Lbl.ALIGNMENT_CENTER    ' 1: Center 0: Left 2: Right
So I thought about creating a small adaptation:
Code: Copy
Dim myAlignment As Int = (4 - Lbl.TextAlignment) Mod 3 ' 0:Center    1:Left     2:Right
 
Upvote 0
Back
Top