methods - How do I make my buttons respond to multiple touches programatically? -


i have created several uibutton programmatically using:

uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];  button.frame = cgrectmake(realx, realy, 64, 64);  [button settitle: str forstate:uicontrolstatenormal];  button.backgroundcolor = greybuttoncolor; 

i want buttons cycle through colors depending on how many times have been touched. ex. grey > green > blue > grey. how go doing using code? code above method created make buttons. should code teach behave based on amount of touches go inside method, or in new one?

i don't know exact code think can tell how solve problem.

  1. register click event each button , assign switchcolor(buttonid) method

  2. you need currentstatebuttonid variable each button save state of button

    • the initial value 0 = gray
    • inside method check
      • if (currentstatebuttonid == 0)
        -> currentstatebuttonid = 1
        -> buttonid color = blue
      • else
        -> currentstatebuttonid = 0
        -> buttonid color = gray

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -