(Swift)
Import UIKitclassViewcontroller:uiviewcontroller {var slider:uislider!func slidervaluechanged (slider:uislider) {println ("Slider ' s new value is \ (slider.value)") } Overridefunc viewdidload () {super.viewdidload () slider= UISlider (Frame:cgrect (x:0Y:0, Width: $, Height: at)) Slider.center=View.center Slider.minimumvalue=0Slider.maximumvalue= -Slider.value= Slider.maximumvalue/2.0 //Customize slider and highlighted with own imageSlider.setthumbimage (UIImage (named:"Thumbnormal"), Forstate:. Normal) Slider.setthumbimage (UIImage (named:"thumbhighlighted"), Forstate:. Highlighted) Slider.addtarget (Self, Action:"slidervaluechanged:", forControlEvents:. valuechanged) View.addsubview (Slider)}}
(OBJECTIVE-C)
#import "ViewController.h"@interfaceViewcontroller () @property (nonatomic, strong) UISlider*Slider;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.slider= [[UISlider alloc] Initwithframe:cgrectmake (0.0f, 0.0f, 200.0f, 23.0f)]; Self.slider.center=Self.view.center; Self.slider.minimumValue=0.0f; Self.slider.maximumValue=100.0f; Self.slider.value= Self.slider.maximumValue/2.0; //Customize slider and highlighted with own image[Self.slider setthumbimage:[uiimage imagenamed:@"Thumbnormal.png"] Forstate:uicontrolstatenormal]; [Self.slider setthumbimage:[uiimage imagenamed:@"Thumbhighlighted.png"] forstate:uicontrolstatehighlighted]; [Self.view AddSubview:self.slider]; [Self.slider addtarget:self Action: @selector (slidervaluechanged:) forcontrolevents:uicontroleventvaluechange d];}
iOS Development Tips-use UISlider to adjust the range of values