ios - button image not changing after click in swift -


i created buttons rating purpose

var distance : cgfloat! = 0.0 var = 1 ;i <= 5;++i {     var profratebtn = uibutton.buttonwithtype(uibuttontype.custom) as! uibutton     profratebtn = uibutton(frame: cgrectmake(235 + distance,266,20,20))     profratebtn.setimage(uiimage(named: "star.png"), forstate: uicontrolstate.normal)     profratebtn.tag =     profratebtn.addtarget(self, action: "doprofrate:", forcontrolevents: uicontrolevents.touchupinside)     self.view.addsubview(profratebtn)     distance = distance + 25.0 cgfloat } 

its when button display image set normal state whenever click on it, not change image star filled

i find on different question , apply different solutions given can not change button image after selected

button action method

func doprofrate(sender : uibutton){     println("btn selected : \(sender.tag)")     sender.setimage(uiimage(named: "star_fill.png"), forstate: uicontrolstate.selected) } 

try

 sender.setimage(uiimage(named: "star_fill.png"), forstate: uicontrolstate.selected) 

change

 sender.setimage(uiimage(named: "star_fill.png"), forstate: uicontrolstate.normal) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -