ios - How to change button colour alternate selection of button? -
this code using ,selectindex bool
if(!selectindex) { click.backgroundcolor=[uicolor colorfromhexstring:@"#ffc400"]; selectindex=yes; } else { click.backgroundcolor=[uicolor graycolor]; selectindex=no; }
my problem when user select button changing colour properly,when user try select button continue previous bool value.
->my requirement when user click button colour have change.
->second when user select same button colour have change.
->button placed inside tableview each button have tag, tried change using tag value failed.any 1 please me....
third party tableview header section:
- (uiview *)mtableview:(tqmultistagetableview *)tableview viewforheaderinsection:(nsinteger)section { uiview *viewheader=[[uiview alloc]initwithframe:cgrectmake(0, 0, tableview.frame.size.width,tableview.frame.size.height)]; uibutton *btnclick; lblhead=[[uilabel alloc]initwithframe:cgrectmake(50,3,150, 50)]; btnclick=[[uibutton alloc]initwithframe:cgrectmake(0,10,30, 30)]; [btnclick addtarget:self action:@selector(touchup:) forcontrolevents:uicontroleventtouchupinside]; btnclick.clipstobounds = yes; btnclick.layer.maskstobounds=yes; btnclick.layer.cornerradius=btnclick.frame.size.height/2; [btnclick setimage:[uiimage imagenamed:@"right.png"] forstate:uicontrolstatenormal]; btnclick.backgroundcolor=[uicolor graycolor]; btnclick.tag=section; [viewheader addsubview:btnclick]; return viewheader; }
select index initially->no.
when user select button colour changed.
now selectindex value yes; when user try select button ,the selectindex values continue true.so when user click button second time colour has been changed. please note button selection should multiple:
you should save state each cell in dictionary or in class
-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{ return [yourarray count]; }
and in
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath nsmutabledictionary *dictionary = [yourarray objectatindex:indexpath.row]; if(dictionary[@“selectindex”] ==no ) { click.backgroundcolor=[uicolor colorfromhexstring:@"#ffc400"]; nslog(@"kishore kumar”); [dictionary setvalue:yes forkey:@“ selectindex”]; }else{ click.backgroundcolor=[uicolor graycolor]; [dictionary setvalue:no forkey:@“selectindex”]; }
Comments
Post a Comment