1

I am working on a radio application, and need to customize the volume tracker colors.

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

If I run the code like this, it causes a weird bug: broken image

But if I comment out the max track color, it works (although no customized color). enter image description here

Any remedies for this? I am running 7.1.1

George L
  • 1,673
  • 2
  • 26
  • 39
  • I ran into this same issue while trying to customize the MPVolume control. Were you able to find a resolution for this? Thank you! – Derek Lee Feb 03 '15 at 10:21
  • Turns out the same question was asked and I found the solution at the follow SO link to be helpful: http://stackoverflow.com/questions/22345668/uislider-setmaximumtracktintcolor-in-ios-7-1 – Derek Lee Feb 03 '15 at 10:41

1 Answers1

0

Let's try:

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];
}
nmh
  • 2,497
  • 1
  • 15
  • 27