i want change text of uibutton city .
but not working, can tell me whats problem here? , ibaction setupcitydropdown connected same uibutton.
@ibaction func setupcitydropdown() { let actionsheet = uialertcontroller(title: "which city?", message: "city name", preferredstyle: uialertcontrollerstyle.actionsheet) let cancelactionbutton: uialertaction = uialertaction(title: "cancel", style: .cancel) { action -> void in } let delhiactionactionbutton : uialertaction = uialertaction(title: "delhi", style: uialertactionstyle.default) { action -> void in self.city.settitle("delhi", forstate: uicontrolstate.normal) self.city.sizetofit() } let mumbaiactionactionbutton : uialertaction = uialertaction(title: "mumbai", style: uialertactionstyle.default) { action -> void in self.city.settitle("mumbai", forstate: uicontrolstate.normal) self.city.sizetofit() } let ahmedabadactionbutton : uialertaction = uialertaction(title: "ahmedabad", style: uialertactionstyle.default) { action -> void in self.city.settitle("ahmedabad", forstate: uicontrolstate.normal) self.city.sizetofit() } actionsheet.addaction(cancelactionbutton) actionsheet.addaction(ahmedabadactionbutton) actionsheet.addaction(delhiactionactionbutton) actionsheet.addaction(mumbaiactionactionbutton) self.presentviewcontroller(actionsheet, animated: true, completion: nil) } }
when setup title in ib uibutton, setting not string
, nsattributedstring
. need use setattributedtitle(_:forstate:)
method change instead of settitle(_:forstate:)
@ibaction func setupcitydropdown() { let actionsheet = uialertcontroller(title: "which city?", message: "city name", preferredstyle: .actionsheet) let cancelactionbutton: uialertaction = uialertaction(title: "cancel", style: .cancel) { action in } let delhiactionactionbutton : uialertaction = uialertaction(title: "delhi", style: .default) { action in self.city.setattributedtitle(nsattributedstring(string: "delhi"), forstate: .normal) self.city.sizetofit() } let mumbaiactionactionbutton : uialertaction = uialertaction(title: "mumbai", style: .default) { action in self.city.setattributedtitle(nsattributedstring(string: "mumbai"), forstate: .normal) self.city.sizetofit() } let ahmedabadactionbutton : uialertaction = uialertaction(title: "ahmedabad", style: .default) { action in self.city.setattributedtitle(nsattributedstring(string: "ahmedabad"), forstate: .normal) self.city.sizetofit() } actionsheet.addaction(cancelactionbutton) actionsheet.addaction(ahmedabadactionbutton) actionsheet.addaction(delhiactionactionbutton) actionsheet.addaction(mumbaiactionactionbutton) self.presentviewcontroller(actionsheet, animated: true, completion: nil) } }