Search code examples
iosios7mpvolumeview

Change Color of MPVolumeView Route Button iOS 7


I am designing a Music app for iOS 7 and I want to put the "AirPlay" route selector button directly in my app. I am able to get the button placed just fine, however it doesn't show up because the icon is white and my background is white.

Is there a way to change the color of the Route Button?

Here is the code I'm using to create the button.

self.airPlayButton = [[MPVolumeView alloc] initWithFrame:CGRectZero];
    self.airPlayButton.showsVolumeSlider = NO;
    [self.airPlayButton sizeToFit];
    self.airPlayButton.backgroundColor = [UIColor myGreenColor];
    [self addSubview:self.airPlayButton];

Basically the picture below is what I want, except I want the icon green instead of just it's background.

MPVolumeView Route Button with background changed


Solution

  • Create your own image and Try setRouteButtonImage:forState: Assigns a button image to the specified control states.

    - (void)setRouteButtonImage:(UIImage *)image forState:(UIControlState)state
    

    Parameters

    image - The image to associate with the specified states.

    state - The control state with which to associate the image.

    Discussion

    Use this to customize the appearance of the route button when it is enabled, disabled, highlighted, and so on.

    Available in iOS 6.0 and later.