objective c - Special tag for UIButton? -
i have 3 different uibuttons each image grouped. have ids each image. right now, have special id each image, , set button tag.
i want change background image of 1 selected when tap it. problem is, 3 buttons have same tag cannot change right button's background image.
here's have:
uibutton *likebutton = [uibutton buttonwithtype:uibuttontypecustom]; [likebutton setbackgroundcolor:[uicolor clearcolor]]; [likebutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button.png"] forstate:uicontrolstatenormal]; [likebutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button_hit.png"] forstate:uicontrolstateselected]; [likebutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button_hit.png"] forstate:uicontrolstatehighlighted]; [likebutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button_hit.png"] forstate:uicontrolstatedisabled]; [likebutton setframe:cgrectmake(13, 52 + (285 * count), 51, 55)]; [likebutton addtarget:self action:@selector(likedudle:) forcontrolevents:uicontroleventtouchdown]; [likebutton settag:theidint]; [likebutton settitle:@"no_like" forstate:uicontrolstatenormal]; [scrollview addsubview:likebutton]; - (ibaction)likedudle: (id)sender { nsinteger tagid = ((uicontrol*)sender).tag; uibutton *tempbutton = (uibutton*)[scrollview viewwithtag:tagid]; nslog(@"likedudle: %d // %@", tagid, tempbutton.titlelabel.text); if ([tempbutton.titlelabel.text isequaltostring:@"no_like"]) { [tempbutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button_hit.png"] forstate:uicontrolstatenormal]; [tempbutton settitle:@"like" forstate:uicontrolstatenormal]; } else if ([tempbutton.titlelabel.text isequaltostring:@"like"]) { [tempbutton setbackgroundimage:[uiimage imagenamed:@"icon_like_button.png"] forstate:uicontrolstatenormal]; [tempbutton settitle:@"no_like" forstate:uicontrolstatenormal]; } is there better way in doing this?
thanks, coulton
if have fewer 10 images, give ith button tag i*10+image.tag. can retrieve image.tag button.tag % 10 , button tags unique. can retrieve button information int b = button.tag/10.
also, can access button's image's tag button.backgroundimage.tag, button have own separate tagging system, depending on uses.
Comments
Post a Comment