(1) The left and right side of the slider background can set the previous page of the next page of the picture;
(2) The track picture of the slider can be set to a gradient and so on.
(3) slider because the value can interact, so addtarget: The method is very important, where the event value changes uicontroleventvaluechanged more special, in fact, and the button's press event is a property, is an event just.
#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller{//Should be followed by GetValue: method to invoke this object, So we have to get the global variable UILabel *label1;} -(void) Viewdidload {//Instantiate a slider bar UISlider *sli1=[[uislider Alloc]init]; Sets the position and size of the control without affecting the size of the control itself, but when the height is set to 0, the slider cannot be dragged Sli1.frame=cgrectmake (30, 30, 300, 60); Set the value sli1.value=0.8; Set the minimum value sli1.minimumvalue=1; Set the maximum value of sli1.maximumvalue=10; Setting has slipped over one end of the slide bar color Sli1.minimumtracktintcolor=[uicolor Redcolor]; Set not to slide past one end of slide bar color Sli1.maximumtracktintcolor=[uicolor Blackcolor]; Set the minimum value one end of the picture, squeeze the slider width sli1.minimumvalueimage=[uiimage imagenamed:@ "1.png"]; Set the maximum value one end of the picture, squeeze the slider width sli1.maximumvalueimage=[uiimage imagenamed:@ "2.png"]; Set the slider color, seemingly invalid, may be the default when the picture, has covered the color sli1.thumbtintcolor=[uicolor yellowcolor]; The settings have been slid past one end of the slide bar background picture, will overwrite the previous color, the following same [Sli1 setminimumtrackimage:[uiimage imagenamed:@ "3.png"] forstate: UIControlStateNormal]; Set not to slide over one end slide background picture [sli1 setmaximumtrackimage:[uiimage imagenamed:@ "LoGo.png "] forstate:uicontrolstatenormal]; Set slider picture background [sli1 setthumbimage:[uiimage imagenamed:@ "1.png"] forstate:uicontrolstatenormal]; The most important thing is to do the corresponding action according to the sliding event//here and the button is similar, but the button event is pressed, and here the event is the uicontroleventvaluechanged value change is the event [Sli1 addtarget:self action:@ Selector (getValue1:) forcontrolevents:uicontroleventvaluechanged]; Set a label to display the value of the change in real time//get the global variable on it, so this is not UILabel *label1, and the direct initialization can be Label1=[[uilabel Alloc]initwithframe:cgrectmake (30, 100, 300, 50)]; [email protected] "value"; [Self.view Addsubview:sli1]; [Self.view Addsubview:label1]; [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.} -(void) GetValue1: (ID) sender{uislider *sli2= (UISlider *) sender; Label1.text=[nsstring stringwithformat:@ "%f", Sli2.value];} @end
An introduction to the properties of the "iOS Dev-11" UISlider Slider and the real-time display of change values in the tag union