Sunday 15 May 2011

ios - change the UIButton image in UITableView UIButton click -



ios - change the UIButton image in UITableView UIButton click -

in uitableview cellforrowatindexpath create 1 button 1 image. write action button click alter button images. here code.

buttonimage = [uiimage imagenamed:@"work_exe_old.png"]; mybutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; mybutton.frame = cgrectmake(250,10,34,34); mybutton.tag=22; [mybutton setbackgroundimage:buttonimage forstate:uicontrolstatenormal]; [mybutton addtarget:self action:@selector(select_id:)forcontrolevents:uicontroleventtouchdown]; - (ibaction)select_id:(id)search { uibutton *tempbtn =(uibutton *) search; [tempbtn setimage:[uiimage imagenamed:@"work_exe.png"] forstate:uicontrolstatenormal]; }

clicked button images changed(work_exe.png). wen click same button 1 time again means image want alter (work_exe_old.png) check box in tableview. how can accomplish tis

instead of doing in way can customise code much better. check code below:

buttonimage = [uiimage imagenamed:@"work_exe.png"]; buttonimageselected = [uiimage imagenamed:@"work_exe_old.png"]; mybutton = [uibutton buttonwithtype:uibuttontypecustom]; mybutton.frame = cgrectmake(250,10,34,34); mybutton.tag=22; [mybutton setbackgroundimage:buttonimage forstate:uicontrolstatenormal]; [mybutton setbackgroundimage:buttonimageselected forstate:uicontrolstateselected]; [mybutton addtarget:self action:@selector(select_id:)forcontrolevents:uicontroleventtouchdown];

and can implement selector method this:

-(ibaction)select_id:(uibutton *) tempbtn { [tempbtn setselected:! tempbtn.selected]; }

ios objective-c iphone uitableview

No comments:

Post a Comment