问题
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
.
回答1:
To change the color of mimimum track
of slider
@property(nonatomic, strong) IBOutlet UISlider *slider;
[self.fontSlider setMinimumTrackTintColor:[UIColor grayColor]];
回答2:
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.
回答3:
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];
}
}
}
回答4:
You could update the tint color of the dot by setting thumbTintColor
来源:https://stackoverflow.com/questions/29845085/how-to-add-different-color-in-a-ui-slider-in-ios