Ios 如何设置MPVolumeView的色调?

Ios 如何设置MPVolumeView的色调?,ios,objective-c,media-player,uislider,mpvolumeview,Ios,Objective C,Media Player,Uislider,Mpvolumeview,如何设置MPVolumeView的色调 我看到这个方法: setMinimumTrackTintColor: 财产呢 minimumTrackTintColor minimumTrackTintColor 但是,使用这两种方法中的任何一种都会引发异常 有人告诉我需要打电话 setMinimumTintColor 或者设置属性 minimumTrackTintColor minimumTrackTintColor 在底层的UISlider上,我不知道如何做到这一点 谢谢 在iO

如何设置MPVolumeView的色调

我看到这个方法:

setMinimumTrackTintColor: 
财产呢

minimumTrackTintColor
minimumTrackTintColor 
但是,使用这两种方法中的任何一种都会引发异常

有人告诉我需要打电话

setMinimumTintColor 
或者设置属性

minimumTrackTintColor
minimumTrackTintColor 
在底层的UISlider上,我不知道如何做到这一点


谢谢

在iOS 7中,您只需更改
MPVolumeView的滑块颜色,如下所示:

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];

希望这能有所帮助。

我已经搜索了很长时间的答案,因为在我的应用程序中,我需要动态设置volumeView颜色。由于UISlider提供了一种更改其色调颜色的方法,因此可以在MPVolumeView子视图中循环,直到找到UISlider类的实例,然后在此实例上进行操作

以下是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
            }
        }
    }
结果:


这对我改变路线按钮的颜色也很有效:

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: [])
}

这非常有效,谢谢!我不知道我以前是怎么错过了那处房产的:虽然这起作用,但它并不完整。route按钮不使用色调。别忘了它不仅仅是一个底层UI滑块,还有一个route按钮。