How to change the tintcolor of the slider in a MPVolumeView?
-
25-06-2021 - |
Question
How can I change the tintcolor of the slider in a MPVolumeView? Instead of blue I want to display a different color.
Solution
You need to customize UISlider
. You can do it like this:
[slider setMinimumTrackImage:[[UIImage imageNamed:@"redSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
Result:
Here is some backgrounds for sliders and example image how they looks:
Slider backgrounds:
Example:
More information here.
OTHER TIPS
After you alloc
volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(40, 145, 270, 23)];
Just search the MPVolumeView subviews and get the slider
for (id current in volumeView.subviews) {
if ([current isKindOfClass:[UISlider class]]) {
UISlider *volumeSlider = (UISlider *)current;
volumeSlider.minimumTrackTintColor = [UIColor redColor];
volumeSlider.maximumTrackTintColor = [UIColor lightGrayColor];
}
Put the colors you like in UIColor and all done. If you need to customize further, treat volumeSlider as a standard UISlider.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow