How can I set the tint color of a MPVolumeView?
I see the method:
setMinimumTrackTintColor:
and the property
minimumTrackTintColor
however using either of those throws an exception.
I was told I need to call
setMinimumTintColor
or set the property
minimumTrackTintColor
on the underlying UISlider, however I don't know how to do that.
Thanks!
In iOS 7 you simply can change the slider color of a MPVolumeView
like this:
CGRect rect1 = CGRectMake(17, 45, 220, 0);
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:rect1];
volumeView.tintColor = [UIColor colorWithRed:0.0f/255.0f green:255.0f/255.0f blue:127.0f/255.0f alpha:1.0f];
Hope this helps.
I have searched for answer to this for a very long time, because in my app I need to set volumeView colors dynamically. Since UISlider provides a way to change its tint color, you can cycle through MPVolumeView subviews until you find an instance of UISlider class and then operate on this one.
Here is the code in Swift:
func customSlider() {
let temp = mpVolView.subviews
for current in temp {
if current.isKind(of: UISlider.self) {
let tempSlider = current as! UISlider
tempSlider.minimumTrackTintColor = .yellow
tempSlider.maximumTrackTintColor = .blue
}
}
}
Result:
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