customizing styles and sliders for UISlider

Source: Internet
Author: User

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

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.