Finish a project, then to write the time, to share with you is: custom UISlider pictures and sliders, first look at the effect:
Then is implemented, we use UISlider setminimumtrackimage, and Setmaximumtrackimage method to define the picture, these two methods can set the slider to the left and the right of the picture, However, if the same picture is used and the width and the width of the control are basically the same, there will be no consequences of deformation stretching, first look at the code, written in Viewdidload:
Picture of left and right rail
UIImage *stetchlefttrack= [UIImage imagenamed:@ "Brightness_bar.png"];
UIImage *stetchrighttrack = [UIImage imagenamed:@ "Brightness_bar.png"];
Slider picture
UIImage *thumbimage = [UIImage imagenamed:@ "Mark.png"];
UISlider *slidera=[[uislider Alloc]initwithframe:cgrectmake (30, 320, 257, 7)];
Slidera.backgroundcolor = [Uicolor Clearcolor];
slidera.value=1.0;
slidera.minimumvalue=0.7;
slidera.maximumvalue=1.0;
[Slidera Setminimumtrackimage:stetchlefttrack Forstate:uicontrolstatenormal];
[Slidera Setmaximumtrackimage:stetchrighttrack Forstate:uicontrolstatenormal];
Note that the uicontrolstatehightlighted state is added here, or the slider becomes the native control when you drag the slider
[Slidera setthumbimage:thumbimage forstate:uicontrolstatehighlighted];
[Slidera setthumbimage:thumbimage Forstate:uicontrolstatenormal];
Events when the slider is dragged
[Slidera addtarget:self Action: @selector (slidervaluechanged:) forcontrolevents:uicontroleventvaluechanged];
Slide the event after dragging
[Slidera addtarget:self Action: @selector (Sliderdragup:) forcontrolevents:uicontroleventtouchupinside];
[Self.view Addsubview:slidera];
customizing styles and sliders for UISlider