cocoa touch - ios change UIButton image at runtime more than one time -


i using storyboard , want 3 stars priority button, @ first view stars appear off (not shining , means priority =0), when first press button image of 3 not shining stars change 1 star shining, when press button again (which button 3 stars image background) 1 star shining , means priority = 1 (the image changes), , press # 2 two stars shining, , pressing again make 3 stars shining, , in next press starts beginning (none of stars shining).

i used code implement button not know how change image. ?

uibutton *btntwo = [uibutton buttonwithtype:uibuttontyperoundedrect];  uiimage *btnimage = [uiimage imagenamed:@"3star.png"]; [btntwo setimage:btnimage forstate:uicontrolstatenormal];  btntwo.frame = cgrectmake(40, 140, 240, 30);  [self.view addsubview:btntwo]; 

create method called when button pressed:

[btntwo addtarget:self action:@selector(buttonpressed) forcontrolevents:uicontroleventtouchupinside]; 

and if don't want make property declaration button add tag identifier

btntwo.tag = 3; //for ex. 

in method created

-(void) buttonpressed{     uibutton *button = (uibutton*)[self.view viewwithtag:3];     [button setimage:[uiimage imagenamed:@"newimage.png"] forstate:uicontrolstatenormal];  } 

in method provide logic assign correct image based on number of times pressed.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -