1

I am building an iOS application where I am using 2 sliders on the same bar for selecting max and min values. I have taken reference of the below link and I am using Point feedback slider.

Reference Link

Now the problem I am facing is that I want that 10-20 should be of green color and 80-90 should be of red color rest should be black color.

PLease help I am new in iOS.

M Zubair Shamshad
  • 2,741
  • 3
  • 23
  • 45
sof question
  • 93
  • 2
  • 13

4 Answers4

1

To change the color of mimimum track of slider

@property(nonatomic, strong) IBOutlet UISlider   *slider;

 [self.fontSlider setMinimumTrackTintColor:[UIColor grayColor]];
steveSarsawa
  • 1,559
  • 2
  • 14
  • 31
Shubham JAin
  • 593
  • 8
  • 15
0

You have to use images to achieve this. Check this link to see how it is done. You cannot change color by using some property of UISlider.

Also check out sample code in the UICatalog sample code app posted by Apple.

UPDATE: Since you need further clarification, read these lines from docs:

*

The bar on which the thumb rides is referred to as the slider’s track. Slider controls draw the track using two distinct images, which are customizable. The region between the thumb and the end of the track associated with the slider’s minimum value is drawn using the minimum track image. The region between the thumb and the end of the track associated with the slider’s maximum value is drawn using the maximum track image. Different track images are used in order to provide context as to which end contains the minimum value. For example, the minimum track image typically contains a blue highlight while the maximum track image contains a white highlight. You can assign different pairs of track images to each of control states of the slder. Assigning different images to each state lets you customize the appearance of the slider when it is enabled, disabled, highlighted, and so on.

*

So, if you want to change the color continuously, you have to have images of all colors. Put them in a NSArray or NSDictionary(with key as your color name) and use it dynamically.

Community
  • 1
  • 1
blancos
  • 1,576
  • 2
  • 16
  • 38
  • thanks for reply but this link is not helpfully in my task as then I have to hardcore the color the value while be changing continuously and according to this value the color will be set in slider. So I can't use image in my case – sof question Apr 24 '15 at 10:37
0

You can handle this situation inside

- (IBAction)labelSliderChanged:(NMRangeSlider*)sender{

        int sliderValue=sender.lowerValue;
        NSLog(@"slider value = %d", sliderValue);
        if(sliderValue >= 10 && sliderValue <= 20)
        {
            if([self.view respondsToSelector:@selector(setTintColor:)])
    {
        self.view.tintColor = [UIColor greenColor];
    }
        }
        else if(sliderValue >= 80 && sliderValue <= 90)
        {
            if([self.view respondsToSelector:@selector(setTintColor:)])
    {
        self.view.tintColor = [UIColor redColor];
    }
        }
        else{

            if([self.view respondsToSelector:@selector(setTintColor:)])
    {
        self.view.tintColor = [UIColor blackColor];
    }
        }
    }
Tanuj
  • 531
  • 4
  • 10
  • Tanuj thank it work. but seem like you get me wrong I want to change Slider color not the 2 images. that line color I want to change – sof question Apr 24 '15 at 11:28
  • can you please help me in solving this error @Tanuj – sof question Apr 24 '15 at 11:53
  • Thanks tanuj can you please help me in one more problem please it will be very great – sof question Apr 24 '15 at 12:00
  • The color are changing on label value change. But I need was that - like the value of line is 100 the default line color should be red 20 to 30. green from 30 to 40. black from 80 to 90. it should be depends on label value change. right now the color change on label value change – sof question Apr 24 '15 at 12:02
  • we cant change this. I can change with the change in label value, according to the sliding value. – Tanuj Apr 24 '15 at 12:07
  • The link that I have mention have a method to change default blue color to orange but the color display to full line of the slider there is no why from where change the color by range by range. please help me @Tanuj. – sof question Apr 24 '15 at 12:12
  • I want to change background grey color to section of different color – sof question Apr 24 '15 at 12:18
0

You could update the tint color of the dot by setting thumbTintColor