Import UIKit
Class Viewcontroller:uiviewcontroller {
var stepper:uistepper!
var label:uilabel!
Override Func Viewdidload () {
Super.viewdidload ()
The Spinner (Uistepper) control contains two buttons +,-, allows the user to adjust the values according to their preference
Stepper = Uistepper.init ()
Stepper.center = Self.view.center
Set the range of stepper
Stepper.maximumvalue = 10
Stepper.minimumvalue = 1
Set the initial value
Stepper.value = 5
Set the amount of each increment
Stepper.stepvalue = 0.5
Set Stepper You can press and hold interception to change the value
Stepper.iscontinuous = True
Sets whether the stepper is cycled (and then increases from the minimum value to the maximum value)
Stepper.wraps = True
Stepper.addtarget (Self, Action: #selector (ValueChange (sender:)), for:. valuechanged)
Self.view.addSubview (Stepper)
Use the Tintcolor property to set the color of the spinner, while the add-minus symbol icon, background image, middle split line picture can be replaced by their own pictures
Replace "-" and "+" with a custom picture
Stepper.setdecrementimage (UIImage (named: "Sub.png"), for:. Normal)
Stepper.setincrementimage (UIImage (named: "Add.png"), for:. Normal)
Label=uilabel (Frame:CGRect.init (x:100, y:190, width:300, height:30))
Label.text = "Current value is: \ (stepper.value)"
Self.view.addSubview (label)
}
Func ValueChange (sender:uistepper) {
Label.text= "Current value is: \ (stepper.value)"
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
}
Swift Practice--Uistepper