user437064
user437064

Reputation:

Custom UISlider

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

Upvotes: 9

Views: 17695

Answers (3)

Nipun35
Nipun35

Reputation: 275

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];

Upvotes: 11

ehenrik
ehenrik

Reputation: 103

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.

Upvotes: 5

vfn
vfn

Reputation: 6066

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.

Upvotes: 8

Related Questions