iOS Question change button backcolor?

ilan

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

narek adonts

Well-Known Member
Licensed User
Longtime User
Upvote 0

ilan

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