Custom UISlider

17,653

Solution 1

You can go through this tutorial for customizing the controls.

For customizing UISlider,use this piece of code from this tutorial.

UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:@"thumb.png"];

     [[UISlider appearance] setMaximumTrackImage:maxImage 
        forState:UIControlStateNormal];
    [[UISlider appearance] setMinimumTrackImage:minImage 
        forState:UIControlStateNormal];
    [[UISlider appearance] setThumbImage:thumbImage 
        forState:UIControlStateNormal];

Solution 2

Read the documentation: UISlider Class Reference

Have a close look at the following methods:

Changing the Slider’s Appearance

setMinimumTrackImage:forState:
setMaximumTrackImage:forState:
setThumbImage:forState:

For background have a look at UIView documentation.

Solution 3

IF you want some example code I could recommend you to look at Apple's example code project UICatalog. This project gives you some basic knowledge about many of the UI elements. In the example they have a custom slider with different colors to the default UISlider.

Share:
17,653
Admin
Author by

Admin

Updated on July 23, 2022

Comments

  • Admin
    Admin almost 2 years

    How to customize UISlider?(change style,background,...)