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.
register click event each button , assign switchcolor(buttonid) method
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
- if (currentstatebuttonid == 0)
Comments
Post a Comment