ios - How to use UIButton as Toggle Button? -
i trying create toggle button each cell in table. when pressed, change image , when pressed again change image again -- toggle.
in uibutton class don't see selected state.
i'm looking way create toggle button uibutton can change state on each click.
this how i'm doing in rubymotion right using rmq
@fav_button.on(:touch) |sender| puts "pressed fav button id: " + data[:id] + " , name: " + data[:name] #how change state here? end
you can create toggle button easily, need set respective images respective states, after that, can use selected property toggle between these images.
i made pure objective-c code show how can that, can set images anyway in storyboards ou xibs too, check out:
// first, set images normal state , selected state [button setimage:normalimage forstate:uicontrolstatenormal]; [button setimage:selectedimage forstate:uicontrolstateselected]; // don't forget add action handler toggle selected property [button addtarget:self action:@selector(buttontouch:withevent:) forcontrolevents:uicontroleventtouchupinside]; // now, in button action handler, can this: - (void)buttontouch:(uibutton *)abutton withevent:(uievent *)event { button.selected = !button.selected; } i hope can you.
Comments
Post a Comment