6

I have a slider with min value 0 and max value 5(be any value) , i need to display 5 different colors in the same slider ie 0-1 one color, 1-2 another color and so on. Is this possible . Please help me if any idea.

krishna
  • 175
  • 1
  • 2
  • 6

3 Answers3

4

Try this,

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0.0f, 400.0f, 320.0f, 35.0f)];
[slider setMinimumTrackTintColor:[UIColor redColor]]; // Initial color of selection
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[[self view] addSubview:slider];

In target method, you can set the colors

- (void)sliderValueChanged:(UISlider *)slider {

/* 

 Here you check the value of slider from [slider value] call;

 then set the color of slider by using

 [slider setMinimumTrackTintColor:[UIColor redColor]];

 */
}

Hope this will help you :)

Augustine P A
  • 5,008
  • 3
  • 35
  • 39
1

you will have to use images for that and in the

-(IBAction)sliderValueChanged:(UISlider *)sender
{
 // depending on the value 
 // if value is 1 {
    [mySlider setMinimumTrackImage:[UIImage imageNamed:@"leftImageforValue=1.png"] forState:UIControlStateNormal];
    [mySlider setMaximumTrackImage:[UIImage imageNamed:@"rightImageforValue=1.png"] forState:UIControlStateNormal];
}
Bonnie
  • 4,943
  • 30
  • 34
0

You can place an ImageView with your desired colors under the slider, and set MinTrackTint and MaxTrackTint to ClearColor. Slider will be fully transparent(except the thumb) but functional.

Dobroćudni Tapir
  • 3,082
  • 20
  • 37