Search code examples
iosxcodempmusicplayercontrollermpvolumeview

Using MPVolumeView, my thumb image shows up underneath the default thumb image using setVolumeThumbImage


I am using an MVVolumeView and I am trying to place the default thumb image with my own.

I have a 25 pixel RED square asset that I named VolumeButtonRed.png to test this procedure.

Here is the code where I try to change the thumb image on the slider:

[[self mpVolumeViewParentView] setBackgroundColor:[UIColor clearColor]];
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame:[[self mpVolumeViewParentView] bounds]];
[[self mpVolumeViewParentView] addSubview:myVolumeView];
[myVolumeView setVolumeThumbImage:[UIImage imageNamed:@"VolumeButtonRed"] forState:UIControlStateNormal];
[myVolumeView setVolumeThumbImage:[UIImage imageNamed:@"VolumeButtonRed"] forState:UIControlStateHighlighted];

I also added a view and changed it class to MPVolumeView.

I also added these line to my .h file (and linked the outlet):

@interface NowPlayingViewController : UIViewController   <UITableViewDataSource, UITableViewDelegate>
{
        MPVolumeView *_mpVolumeViewParentView;
}

@property (nonatomic, retain) IBOutlet MPVolumeView *mpVolumeViewParentView;

Here is the result:

enter image description here

As you can see, my red square shows up behind the default thumb button and does not replace it.

What am I doing wrong?


Solution

  • The problem is probably that you have two volume views, one coming from the storyboard and another created in code.