iOS Question change button backcolor?

Discussion in 'iOS Questions' started by ilan, May 26, 2015.

Similar threads

B4i Code Snippet Msgbox with timeout
B4A Tutorial [B4X] Anchors Demonstrated
B4i Code Snippet CSBuilder text direction
B4i Tutorial Background Fetch (Downloads)
B4i Code Snippet Full screen apps
  1. ilan

    ilan Expert Licensed User

    how can i change the button backcolor?

    Code:
    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
     
  2. narek adonts

    narek adonts Well-Known Member 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
     
  3. ilan

    ilan Expert Licensed User

    should be done easier ... only set 2 states with different backcolors...
     
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    Ok.
    Why clr is a string? i think it should be a UIColor.

    You can use no.colortoUIColor
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    try this - NOT TESTED

    Code:
    Sub SetBackgroundImage(b As Button, cr1 As Int , state As Int)
        
    Dim no As NativeObject = b
        no.RunMethod(
    "setBackgroundColor:forState:"Array(no.ColorToUIColor(cr1), state))
    End Sub
     
  6. ilan

    ilan Expert Licensed User

    i guess their is no background color with state in ios but title color works

    Code:
    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: May 26, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice