iOS Question change button backcolor?

ilan

Expert
Licensed User
how can i change the button backcolor?

B4X:
Sub SetBackgroundImage(b As Button, cr1 As String , state As Int)
    Dim no As NativeObject = b
    no.RunMethod("setBackgroundColor:forState:", Array(cr1, state))
End Sub
this doesnot work
 

ilan

Expert
Licensed User
Just use button.color=colors.blue for exemple
If you need to track the touchdown and touchup events you can use my GestureRecognizer class
should be done easier ... only set 2 states with different backcolors...
 

ilan

Expert
Licensed User
Method not found: setBackgroundColor:forState:, target: <UIButton: 0x1569ab40; frame = (50 323.478; 190 62.6087); opaque = NO; gestureRecognizers = <NSArray: 0x1569bce0>; layer = <CALayer: 0x1567a6e0>>
i guess their is no background color with state in ios but title color works

B4X:
Sub SetTitleColor(b As Button, cr1 As Int , state As Int)
    Dim no As NativeObject = b
    no.RunMethod("setTitleColor:forState:", Array(no.ColorToUIColor(cr1), state))
End Sub
use: SetTitleColor(startbtn,Colors.Green,1)

thanks anyway :)

EDIT: i solved it by adding a bitmap to state 1 with the background color i wanted so like this there is only for state 1 a background image and state 0 is the backcolor i choose, thanx
 
Last edited:
Top