Button as a Switch?

Discussion in 'iOS Programming' started by yaboy10holla, Mar 4, 2011.

  1. yaboy10holla macrumors newbie

    Joined:
    Feb 19, 2011
    #1
    Hi guys,

    I am trying to create a button that toggles between two states, that does on thing on the first press, and "un-does it" on the second press. Would anyone like to point me in the right direction? Ive thought of maybe creating a counter that tracks the clicks and then basing an action on whether the count is odd or even, but there has to be an easier and better way then that im sure? thanks!
     
  2. nickculbertson macrumors regular

    nickculbertson

    Joined:
    Nov 19, 2010
    Location:
    Nashville, TN
    #2
    One way to do this is to make two buttons and stack them on top of one another. Then make two methods:
    Code:
    
    -(IBAction)press1{
        //do stuff
        button1.hidden=YES;
        button2.hidden=NO;
    }
    
    -(IBAction)press2{
        //do stuff
        button1.hidden=NO;
        button2.hidden=YES;
    }
    
    
    Nick
     

Share This Page