ios - Buttons in iPad not clickable -
i creating buttons using data array. should following:
override func viewdidload() { super.viewdidload() var xmargin:cgfloat = 20.0 var ytopmargin:cgfloat = 40.0 var = 1 let datatanks = ["button 1", "button 2", "button 3", "button 4", "button 5", "button 6"] index in 0...5 { let button = uibutton() button.tag=index var buttonframe = self.view.frame buttonframe.origin.x += xmargin buttonframe.origin.y += ytopmargin buttonframe.size.width = 200 buttonframe.size.height = 200 button.frame = buttonframe button.layer.cornerradius = 15.0 button.layer.shadowcolor = uicolor(red: 64/255, green: 64/255, blue: 64/255, alpha: 1).cgcolor button.layer.shadowopacity = 0.5 button.layer.shadowradius = 5 button.layer.shadowoffset = cgsizemake(2.0, 2.0) button.layer.zposition = 10 button.backgroundcolor = uicolor.lightgraycolor() button.enabled=false if(index==2) { button.enabled=true button.backgroundcolor = uicolor(red: 153/255, green: 0/255, blue: 0/255, alpha: 1.0) } if(index==3) { button.enabled=true button.backgroundcolor = uicolor(red: 0/255, green: 0/255, blue: 102/255, alpha: 1.0) } button.settitle(datatanks[index], forstate: uicontrolstate.normal) button.titlelabel!.numberoflines = 3; button.addtarget(self, action: #selector(mytestviewcontroller.didtouchbutton), forcontrolevents: uicontrolevents.touchupinside) self.view.addsubview(button) xmargin+=250.0 i+=1 if(i > 3 ) { ytopmargin+=300.0 xmargin=20.0 i=1 } } } func didtouchbutton(sender:uibutton!) { print("button - \(btnsendtag.tag)") }
using above code, few buttons clickable others not. not sure what's causing button not work. can help?
this normal because disactivated other buttons except index 2 , 3.
button.enabled=false
^ 'what's causing button not work'
Comments
Post a Comment