iOS Question button textcolor?

Filippo

Expert
Licensed User
Ciao Filippo,

questo è un piccolo esempio.
B4X:
Sub NewButton(Text As String, TextSize As Int, TextFont As Font, Event As String) As Button
    Dim btn As Button
    btn.Initialize(Event, btn.STYLE_SYSTEM)
    btn.SetBorder(1, Colors.Black, 3)
    btn.CustomLabel.Font = Font.CreateNew(TextSize)
    btn.Text = Text
    Return btn
End Sub
 

fifiddu70

Well-Known Member
Licensed User
no filippo i need to change textcolor, or background color, your code i have = change olny border not textcolor
 

Filippo

Expert
Licensed User
and then try this ;)
B4X:
Sub NewButton(Text As String, TextSize As Int, TextFont As Font, Event As String) As Button
    Dim btn As Button
    btn.Initialize(Event, btn.STYLE_SYSTEM)
    btn.SetBorder(1, Colors.Black, 3)
    btn.CustomLabel.Font = Font.CreateNew(TextSize)
    btn.CustomLabel.TextColor = Colors.Green
    btn.Color = Colors.Red
    btn.Text = Text
    Return btn
End Sub
 

fifiddu70

Well-Known Member
Licensed User
ok for change background, not ok for change the texcolor, see my little code:
B4X:
   btnascolta.Initialize("btnascolta",btnascolta.STYLE_SYSTEM)
    btnascolta.Text = "ASCOLTA"
    btnascolta.SetBorder(1, Colors.Black, 3)
    btnascolta.CustomLabel.Font = Font.CreateNew(20)
    btnascolta.CustomLabel.TextColor = Colors.Red
    btnascolta.Color = Colors.Yellow
the problem now is the textcolor, not change color.
 

klaus

Expert
Licensed User
B4X:
btnascolta.InitializeCustom("btnascolta",Colors.Red, Colors.Blue)
btnascolta.Text = "ASCOLTA"
btnascolta.SetBorder(1, Colors.Black, 3)
btnascolta.CustomLabel.Font = Font.CreateNew(20)
btnascolta.Color = Colors.Yellow
 

fifiddu70

Well-Known Member
Licensed User
thanks Klaus, now work fine, thanks Filippo.
if i need to change text colors in the picker?
 
Last edited:

mrossen

Active Member
Licensed User
Hi,

I have a button created with the designer. I want to change the text color when I have clicked the button
B4X:
Sub ButtonDanish_Click
   
    ButtonDanish.Color = Colors.RGB(51,153,255)
    ButtonDanish.CustomLabel.TextColor = Colors.White
 

End Sub
The background color changes but not the text color.

I also tried Klaus examble but it seems to make a new button

Mogens
 

mrossen

Active Member
Licensed User
Hi Again

This is from the doc.

How can I Customize the label if it is Read Only?

CustomLabel AsLabel [read only]

Gets the inner label. You can use this property to customize custom buttons.

Maybe this is why it not can get the above to Work ?

Mogens
 

klaus

Expert
Licensed User
I confirm !
Changing the text color insides the Button1_Click event has no effect.
With the code below:
B4X:
Private Sub Button1_Click
    Button1.Color = Colors.Red
    Button1.CustomLabel.TextColor = Colors.White

    Button2.Color = Colors.Red
    Button2.CustomLabel.TextColor = Colors.White
End Sub
The Button1 and Button2 background colors are changed.
But only the Button2 text color is changed.

Attached the test program.
 

Attachments

Erel

Administrator
Staff member
Licensed User
How can I Customize the label if it is Read Only?
The property is read-only. The label itself is not read-only.

There are two ways to set the color used in the "pressed state":

1. With the designer:



2. With NativeObject:
B4X:
'state: 0 = normal, 1 = pressed, 2 = disabled
Sub SetButtonTextColor(btn As Button, clr As Int, state As Int)
   Dim no As NativeObject = btn
   no.RunMethod("setTitleColor:forState:", Array(no.ColorToUIColor(clr), state))
End Sub

SetButtonTextColor(Button1, Colors.Grean, 1)
 
Top