ios - Implementing UIButtons for selection in Swift -
i'm new ios development , i'm working on fire safety app. give user option of 3 risk levels: low, medium , high using (i suppose) 3 uibuttons user can tap, , ever 1 tap turn colour.
i've managed 3 uibuttons working, , can change colour when tapped if tap can't previous button change , i've had difficulties getting value them (for example when submitted if user pressed low use number 2 calculations)
to show did quick drawing: button example
thanks :)
==== edit ====
i using segmented control instead of uibuttons this. need know how use them in if statement
@iboutlet var riskchoice: uisegmentedcontrol! @iboutlet var valuelabel: uilabel! @iboutlet var calcbutton: uibutton! @ibaction func calculate(sender: uibutton) { if (riskchoice.selectedsegmentindex == 0){ valuelabel.text = string("low") }
nothing appears in label have set up.. direct me here?
you can reset 3 buttons default state when of button tapped , highlight current button.
@ibaction func buttonclicked(sender: uibutton) { /** reset button default state*/ resetallbuttons() /** highlight current button */ sender.backgroundcolor = uicolor.redcolor() sender.titlecolor = uicolor.whitecolor() } private func resetallbuttons() { button1.backgroundcolor = uicolor.clearcolor() button1.titlecolor = uicolor.blackcolor() /// or use : button1.settitlecolor(uicolor.blackcolor, forstate: .normal) button2.backgroundcolor = uicolor.clearcolor() button2.titlecolor = uicolor.blackcolor() button3.backgroundcolor = uicolor.clearcolor() button3.titlecolor = uicolor.blackcolor() }
Comments
Post a Comment