iOS Question Can't change alignment of text in button

RVP

Active Member
Licensed User
Longtime User
I have added a button to my page in Designer, it is marked as Style Custom, then in my code I am doing:
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
        btnCompany.CustomLabel.TextAlignment = btnCompany.CustomLabel.ALIGNMENT_LEFT
        btnLocation.CustomLabel.TextAlignment = btnLocation.CustomLabel.ALIGNMENT_LEFT
End Sub

But the aligment remains centered
 

RVP

Active Member
Licensed User
Longtime User
B4X:
    lblbtnCompany.Initialize("lblbtnCompany")
    lblbtnLocation.Initialize("lblbtnLocation")
    lblbtnCompany.TextAlignment = lblbtnCompany.ALIGNMENT_LEFT
    lblbtnLocation.TextAlignment = lblbtnLocation.ALIGNMENT_LEFT
    lblbtnCompany.Text = cid
    lblbtnLocation.Text = loca
   
    btnCompany.Text = lblbtnCompany
    btnLocation.Text = lblbtnLocation

That gives a warning Object Converted to String This is probably a programming mistake and then displays the object information when run instead of the actual txt
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
why dont you use label as button ? IS there any special reason for you to use button instead of label ?
B4X:
    lblbtnCompany.Initialize("lblbtnCompany")
    lblbtnLocation.Initialize("lblbtnLocation")
    lblbtnCompany.TextAlignment = lblbtnCompany.ALIGNMENT_LEFT
    lblbtnLocation.TextAlignment = lblbtnLocation.ALIGNMENT_LEFT
    lblbtnCompany.Text = cid
    lblbtnLocation.Text = loca
  
    btnCompany.Text = lblbtnCompany
    btnLocation.Text = lblbtnLocation

That gives a warning Object Converted to String This is probably a programming mistake and then displays the object information when run instead of the actual txt
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
why dont you use label as button ? IS there any special reason for you to use button instead of label ?

the button has different settings like "pressed text color" or "pressed background image",...
would also interest me why the code above does not work

and also why there is no "Text aligment" in the designer when i choose a button?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
the button has different settings like "pressed text color" or "pressed background image",...
would also interest me why the code above does not work

and also why there is no "Text aligment" in the designer when i choose a button?

dont know the answer but maybe you can use timer for what you want with an interval of 500 maybe
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i am doing it allready like you suggest (via timer) but i think that it would be good for us to know why this code doesnot work and what is the right code.
maybe @Erel could bring some light to the darkness :)
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
It is always better to start a new thread for a new question.

It is the same question as above (title)
Thatswhy i didnot start a new thread.

Just searched by my self for "button alignment - b4i" and this thread was in first place so i thought it would be good to have an answer to this thread...
 
Upvote 0
Top