OBJECTIVE-C: 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     // takes the value of the slider and assigns it to the step, making the step and slider event states 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, step size can be set) 2 -(ibaction) Steppervaluechange: (uistepper *) sender3{4     NSLog ( @" %LF " , sender.value); 5     // takes the value of the stepping and assigns it to the slider, making the Step and slider events the same state 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 (status State only has two forms: on, off) 2 -(ibaction) Switchvaluechange: (Uiswitch *) sender3{4     NSLog (  @ "%@", Sender.ison? @" Open ":@" off "); 5 }

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

The source code is as follows:

1 //VIEWCONTROLLER.M2 //02-Image Browser3 //4 //Created by Ma C on 15/8/27.5 //Copyright (c) 2015 BJSXT. All rights reserved.6 //7 8 #import "ViewController.h"9 Ten @interfaceViewcontroller () One@property (Weak, nonatomic) Iboutlet UILabel *Labeltitle; A@property (Weak, nonatomic) Iboutlet UILabel *Labelinfo; -@property (Weak, nonatomic) Iboutlet Uiimageview *ImageView; -@property (Weak, nonatomic) Iboutlet Uistepper *Stepper; the@property (Weak, nonatomic) Iboutlet UISlider *Slider; -@property (strong,nonatomic) Nsarray *Imageinfos; -@property (assign,nonatomic) Nsinteger index;//Displays the index of the current picture -@property (assign,nonatomic) Nsinteger total;//Number of pictures + @end -  + @implementationViewcontroller A-(Ibaction) Steppervaluechange: (Uistepper *) Sender at { - [Self.slider SetValue:sender.value]; -Self.index =[Self.stepper value]; - [self setImageIndex:self.index]; - } --(Ibaction) Slidervaluechange: (UISlider *) Sender in { - [Self.stepper SetValue:sender.value]; toSelf.index =[Self.slider value]; + [self setImageIndex:self.index]; - } the  *- (void) Viewdidload { $ [Super Viewdidload];Panax Notoginseng     //Loading picture information -NSString *path = [[NSBundle mainbundle] Pathforresource:@"Images"OfType:@"plist"]; theSelf.imageinfos =[Nsarray Arraywithcontentsoffile:path]; +      A      the     //Initialize +Self.total =[Self.imageinfos Count]; -Self.index =0; $      $Self.stepper.minimumValue =0; -Self.stepper.maximumValue = Self.total-1; -Self.stepper.value =0; theSelf.stepper.stepValue =1; -     WuyiSelf.slider.minimumValue =0; theSelf.slider.maximumValue = Self.total-1; -Self.slider.value =0; Wu      -  AboutSelf.imageView.contentMode =Uiviewcontentmodescaleaspectfit; $[Self Setimageindex:0]; -      - } -  A-(void) Setimageindex: (nsuinteger) Index + { the      -     //Take out the dictionary in the array $Nsdictionary *dicimage =Self.imageinfos[index]; theNSString *imagename = [Dicimage objectforkey:@"icon"]; theNSString *imagetitle = [Dicimage objectforkey:@"title"]; the      the     //set the displayed picture -Self.imageView.image =[UIImage imagenamed:imagename]; in      the     //set the caption of the displayed picture theSelf.labelTitle.text =Imagetitle; About      the     //Set Current information: Index/Total theSelf.labelInfo.text = [NSString stringWithFormat:@"%ld/%ld", self.index+1, self.total]; the } +  -- (void) didreceivememorywarning { the [Super didreceivememorywarning];Bayi     //Dispose of any resources the can be recreated. the } the  - @end

OBJECTIVE-C: Basic use of stepping uistepper, sliding block uislider, switch uiswitch

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.