문제

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:

enter image description here

This worked for me to change the route button color too:

volumeView.tintColor = .green
if let routeButton = volumeView.subviews.compactMap({ $0 as? UIButton }).first,
    let image = routeButton.image(for: .normal) {
    routeButton.setImage(image.withRenderingMode(.alwaysTemplate), for: [])
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top