IOS: Basic use of stepping uistepper, sliding block uislider, switch uiswitch

Source: Internet
Author: User

Stepping Uistepper, sliding block UISlider: When they are triggered as events, their values change. Because of this, when the event is triggered, you can flip through a picture,,,

Stepping Uistepper:

@property (nonatomic) double minimumvalue; Default 0. Must is less than MaximumValue

@property (nonatomic) double maximumvalue; Default 100. Must be greater than minimumvalue

@property (nonatomic) double stepvalue; Default 1. must be greater than 0, distance per step

1//Slider trigger event (value change, Range Mininum~maxnum) 2-(Ibaction) Slidervaluechange: (UISlider *) Sender3 {4     NSLog (@ "%LF", Sender.value) 5     //The value of the slider is taken out and assigned to the stepping so that the step and slide block event state is the same 6     [Self.stepper setvalue:sender.value];7}

Slide Block Uistepper:

@property (nonatomic) float value; Default 0.0. This value would be pinned to Min/max

@property (nonatomic) float MinimumValue; Default 0.0. The current value could change if outside new min value

@property (nonatomic) float MaximumValue; Default 1.0. The current value could change if outside new max value

1//Step trigger event (value change, range mininum~maxnum, stepping size can be set step value) 2-(Ibaction) Steppervaluechange: (Uistepper *) Sender3 {4     NSLog (@ "%lf", Sender.value); 5     //Remove the stepping value and assign it to the slider so that the step and slider event states are the same 6     [Self.slider setvalue:sender.value];7}

Switch Uiswitch:

@property (Nonatomic,getter=ison) BOOL on; There are two states, open on or off off

1//Switch trigger event (State states only two forms: on, off) 2-(Ibaction) Switchvaluechange: (Uiswitch *) Sender3 {4     NSLog (@ "%@", [email Protected] "open": @ "Off"); 5}

The following is a picture browser made with stepping and sliding blocks, switches

The source code is as follows:

 1//VIEWCONTROLLER.M 2//02-Image Browser 3//4//Created by Ma C on 15/8/27. 5//Copyright (c) 2015 BJSXT. All rights reserved. 6//7 8 #import "ViewController.h" 9 @interface Viewcontroller () One @property (weak, nonatomic) Iboutlet UILabel *lab Eltitle;12 @property (Weak, nonatomic) Iboutlet UILabel *labelinfo;13 @property (weak, nonatomic) Iboutlet Uiimageview *im Ageview;14 @property (Weak, nonatomic) Iboutlet uistepper *stepper;15 @property (weak, nonatomic) Iboutlet UISlider *slide R;16 @property (strong,nonatomic) nsarray *imageinfos;17 @property (assign,nonatomic) Nsinteger index;//Show index of current picture 18 @ Property (assign,nonatomic) nsinteger total;//pictures @end20 @implementation ViewController22-(ibaction) Steppervaluechange: (Uistepper *) sender23 {[Self.slider setvalue:sender.value];25 self.index = [Self.stepper val  ue];26 [Self setimageindex:self.index];27}28-(ibaction) Slidervaluechange: (UISlider *) sender29 {[Self.stepper] setvalue:sender.value];31 sElf.index = [Self.slider value];32 [Self setimageindex:self.index];33}34-(void) Viewdidload {$ [Super Viewdi DLOAD];37//Load picture information nsstring *path = [[NSBundle mainbundle] pathforresource:@ "Images" oftype:@ "plist"];39 sel F.imageinfos = [Nsarray arraywithcontentsoffile:path];40 41 42//initialization of self.total = [Self.imageinfos count     ];44 Self.index = 0;45 Self.stepper.minimumValue = 0;47 Self.stepper.maximumValue = self.total-1;48 Self.stepper.value = 0;49 Self.stepper.stepValue = 1;50 Self.slider.minimumValue = 0;52 self.slider. MaximumValue = self.total-1;53 Self.slider.value = 0;54, Self.imageView.contentMode = Uiviewcontentmode scaleaspectfit;57 [Self setimageindex:0];58}60-(void) Setimageindex: (Nsuinteger) index62 {63 64//Remove The dictionary in the array is nsdictionary *dicimage = self.imageinfos[index];66 nsstring *imagename = [dicimage objectforkey:@ "icon"]; NSString *imagetitle = [Dicimage objectforkey:@ "title"];68 69//settings display picture of Self.imageView.image = [UIImage imagenamed:imagename]  ; 71 72//Set the caption of the displayed picture Self.labelTitle.text = imagetitle;74 75//Set Current information: Index/Total Self.labelInfo.text  = [NSString stringwithformat:@ "%ld/%ld", self.index+1,self.total];77}78-(void) didreceivememorywarning {[Super] didreceivememorywarning];81/Dispose of any resources the can be recreated.82}83 @end

IOS: Basic use of stepping uistepper, sliding block uislider, switch uiswitch

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.