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.
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 :)
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With