1

我正在开发一个收音机应用程序,需要自定义音量跟踪器颜色。

    myVolumeView = [[MPVolumeView alloc] initWithFrame: CGRectMake(26, 292, 268, 23)];

    [self.view addSubview: myVolumeView];
    for (id current in myVolumeView.subviews) {
        if ([current isKindOfClass:[UISlider class]]) {
            UISlider *volumeSlider = (UISlider *)current;
            volumeSlider.minimumTrackTintColor = [UIColor redColor];
            volumeSlider.maximumTrackTintColor = [UIColor lightGrayColor];
            //[volumeSlider setThumbImage:[UIImage imageNamed:@"volTrack.png"] forState:UIControlStateNormal];
        }
    }

如果我像这样运行代码,它会导致一个奇怪的错误:损坏的图像

但是如果我注释掉最大轨道颜色,它就可以工作(尽管没有自定义颜色)。在此处输入图像描述

有什么补救措施吗?我正在运行 7.1.1

4

1 回答 1

0

我们试试看:

if ([current isKindOfClass:[UISlider class]]) {
     UISlider *volumeSlider = (UISlider *)current;
     volumeSlider.minimumTrackTintColor = [UIColor redColor];
     volumeSlider.maximumTrackTintColor = [UIColor lightGrayColor];
     [volumeSlider setThumbImage:[UIImage imageNamed:@"volTrack.png"] forState:UIControlStateNormal];

     // I think you should set these properties:
     [slider setMinimumTrackImage:[[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filled ofType:@"png" inDirectory:@"MDAudioPlayer.bundle"]]stretchableImageWithLeftCapWidth:5 topCapHeight:3] forState:UIControlStateNormal];
     [slider setMaximumTrackImage:[[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:empty ofType:@"png" inDirectory:@"MDAudioPlayer.bundle"]] stretchableImageWithLeftCapWidth:5 topCapHeight:3] forState:UIControlStateNormal];
}
于 2014-05-04T09:55:56.360 回答