swift - how to update ui after changing property of custom class -
i created custom class customview
, subclass of uiview
.
class customview: uiview{ var buttonnumber: int = 0 override init(frame: cgrect) { super.init(frame: frame) } // storyboard loader uses @ runtime. required init?(coder adecoder: nscoder) { super.init(coder: adecoder) } override func awakefromnib() { buttons in 0...2{ let btn = uibutton(frame: cgrect(x: (self.frame.width) * (cgfloat(buttons)/3) + 1,y: 1,width: self.frame.width/3 - 2,height: self.frame.height - 2)) btn.addtarget(self, action: #selector(buttontapped(sender:)), for: .touchupinside) btn.tag = buttons self.addsubview(btn) } } func buttontapped(sender: uibutton!){ self.buttonnumber = sender.tag } }
now, in viewcontroller, added uiview
"changed class customview
" & uilabel
'mylabel'.
what want title of uilabel
'mylabel' changes whenever property 'buttonnumber' changes. how can that?
update: i'm trying make custom uisegmentedcontrol using uiview , buttonnumber property represents selected segment. of things made static. want access selectedsegment property through viewcontroller. how can achieve functionality?
Comments
Post a Comment