iOS Question button textcolor?

fifiddu70

Well-Known Member
Licensed User
Longtime User
i need to change a textcolor and background color in button, the code?
 
D

Deleted member 103

Guest
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
 
Upvote 0

fifiddu70

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

Deleted member 103

Guest
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
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

klaus

Expert
Licensed User
Longtime 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
 
Upvote 0

fifiddu70

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

mrossen

Active Member
Licensed User
Longtime 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
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Again

This is from the doc.

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

19.png
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
 
Upvote 0

klaus

Expert
Licensed User
Longtime 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

  • ButtonTextColor.zip
    2.2 KB · Views: 209
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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:

SS-2014-12-25_16.14.23.png


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)
 
Upvote 0
Top