ios - Set UIButton state to selected when creating custom UIButton class -


my uibutton has been created , has colors states want.

however, when click it, not remain selected.

all code reading addresses state of button in view controller after ib action. not yet understand touchesbegan method either.

i have repeat 14 times , avoid setting each one..

edit: code:

class appointmentdatepickerambutton: uibutton {     required init(coder adecoder: nscoder) {         super.init(coder: adecoder)         self.settitlecolor(uicolor.graycolor(), forstate: uicontrolstate.normal)         self.settitlecolor(uicolor.redcolor(), forstate: uicontrolstate.highlighted)         self.settitlecolor(uicolor.bluecolor(), forstate: uicontrolstate.selected)       } } 

the thing have add target action button, pass button instance method , set on sender.selected = yes if selecting or sender.selected = !sender.selected if on/off behaviour wanted. in code defined how should selected state, have set control state. remember button can combine multiple states @ same time (for example highlighted , selected).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -