Swift Practice--Uistepper

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.