iOS Developer Library

Developer

MediaPlayer Framework Reference MPVolumeView Class Reference

Options
Deployment Target:

On This Page
Language:

MPVolumeView

Use a volume view to present the user with a slider control for setting the system audio output volume, and a button for choosing the audio output route. When first displayed, the slider’s position reflects the current system audio output volume. As the user drags the slider, the changes update the volume. If the user presses the device volume buttons while sound is playing, the slider moves to reflect the new volume. More...

Inheritance


Import Statement


import MediaPlayer @import MediaPlayer;

Availability


Available in iOS 2.0 and later.
  • sizeThatFits: sizeThatFits: Available in iOS 2.0 through iOS 7.1

    Calculates and returns a size that best fits the receiver’s subviews.

    Declaration

    Objective-C

    - (CGSize)sizeThatFits:(CGSize)size

    Parameters

    size

    The preferred size of the receiver.

    Return Value

    A new size that fits the receiver’s subviews.

    Discussion

    This method overrides the like-named method from the UIView class. It returns the preferred size the volume view needs to display the contained slider. You should not need to override this method.

    Import Statement

    Availability

    Available in iOS 2.0 through iOS 7.1.

  • Determines whether or not the volume slider is visible in the volume view.

    Declaration

    Swift

    var showsVolumeSlider: Bool

    Objective-C

    @property(nonatomic) BOOL showsVolumeSlider

    Discussion

    The volume slider is visible by default. To hide the volume slider, set this property’s value to NOfalse.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 4.2 and later.

  • Determines whether or not the route button is visible in the volume view.

    Declaration

    Swift

    var showsRouteButton: Bool

    Objective-C

    @property(nonatomic) BOOL showsRouteButton

    Discussion

    The route button is visible by default when there is more than one audio output route available. To hide the route button, set this property’s value to NOfalse.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 4.2 and later.

  • Returns the maximum volume image associated with the specified control state.

    Declaration

    Swift

    func maximumVolumeSliderImageForState(_ state: UIControlState) -> UIImage!

    Objective-C

    - (UIImage *)maximumVolumeSliderImageForState:(UIControlState)state

    Parameters

    state

    The control state whose maximum volume image you want. You should specify only one control state value for this parameter.

    Return Value

    The maximum volume image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter.

    Discussion

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the minimum volume image associated with the specified control state.

    Declaration

    Swift

    func minimumVolumeSliderImageForState(_ state: UIControlState) -> UIImage!

    Objective-C

    - (UIImage *)minimumVolumeSliderImageForState:(UIControlState)state

    Parameters

    state

    The control state whose minimum volume image you want. You should specify only one control state value for this parameter.

    Return Value

    The maximum volume image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter.

    Discussion

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Assigns a maximum volume slider image to the specified control states.

    Declaration

    Swift

    func setMaximumVolumeSliderImage(_ image: UIImage!, forState state: UIControlState)

    Objective-C

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

    Parameters

    image

    The maximum volume slider image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    The orientation of the track image must match the orientation of the slider control. To facilitate the stretching of the image to fill the space between the thumb and end point, track images are usually defined in three regions. A stretchable region sits between two end cap regions. The end caps define the portions of the image that remain as is and are not stretched. The stretchable region is a 1-point wide area between the end caps that can be replicated to make the image appear longer.

    To define the end cap sizes for a slider, assign an appropriate value to the image’s capInsets property. For more information about how this value defines the regions of the slider, see the UIImage Class Reference.

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Assigns a minimum volume slider image to the specified control states.

    Declaration

    Swift

    func setMinimumVolumeSliderImage(_ image: UIImage!, forState state: UIControlState)

    Objective-C

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

    Parameters

    image

    The minimum volume slider image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    The orientation of the track image must match the orientation of the slider control. To facilitate the stretching of the image to fill the space between the thumb and end point, track images are usually defined in three regions. A stretchable region sits between two end cap regions. The end caps define the portions of the image that remain as is and are not stretched. The stretchable region is a 1-point wide area between the end caps that can be replicated to make the image appear longer.

    To define the end cap sizes for a slider, assign an appropriate value to the image’s capInsets property. For more information about how this value defines the regions of the slider, see the UIImage Class Reference.

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Assigns a thumb image to the specified control states.

    Declaration

    Swift

    func setVolumeThumbImage(_ image: UIImage!, forState state: UIControlState)

    Objective-C

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

    Parameters

    image

    The thumb image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the drawing rectangle for the slider’s track.

    Declaration

    Swift

    func volumeSliderRectForBounds(_ bounds: CGRect) -> CGRect

    Objective-C

    - (CGRect)volumeSliderRectForBounds:(CGRect)bounds

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The computed drawing rectangle for the volume slider track. This rectangle corresponds to the entire length of the track between the minimum and maximum value images.

    Discussion

    The returned rectangle is used to scale the track and thumb images during drawing.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the thumb image associated with the specified control state.

    Declaration

    Swift

    func volumeThumbImageForState(_ state: UIControlState) -> UIImage!

    Objective-C

    - (UIImage *)volumeThumbImageForState:(UIControlState)state

    Parameters

    state

    The control state whose thumb image you want. You should specify only one control state value for this parameter.

    Return Value

    The thumb image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter.

    Discussion

    For a description of slider and thumb images, see Customizing the Volume Slider’s Appearance.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the drawing rectangle for the volume slider’s thumb image.

    Declaration

    Swift

    func volumeThumbRectForBounds(_ bounds: CGRect, volumeSliderRect rect: CGRect, value value: Float) -> CGRect

    Objective-C

    - (CGRect)volumeThumbRectForBounds:(CGRect)bounds volumeSliderRect:(CGRect)rect value:(float)value

    Parameters

    bounds

    The bounding rectangle of the receiver.

    rect

    The drawing rectangle for the receiver’s track, as returned by the volumeSliderRectForBounds: method.

    value

    The current value of the volume slider.

    Return Value

    The computed drawing rectangle for the thumb image.

    Discussion

    The rectangle you return should reflect the size of your thumb image and its current position on the slider’s track.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the button image associated with the specified control state.

    Declaration

    Swift

    func routeButtonImageForState(_ state: UIControlState) -> UIImage!

    Objective-C

    - (UIImage *)routeButtonImageForState:(UIControlState)state

    Parameters

    state

    The control state whose thumb image you want. You should specify only one control state value for this parameter.

    Return Value

    The button image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter.

    Discussion

    Use this method to retrieve the corresponding button image for a specific state.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Returns the drawing rectangle for the route button.

    Declaration

    Swift

    func routeButtonRectForBounds(_ bounds: CGRect) -> CGRect

    Objective-C

    - (CGRect)routeButtonRectForBounds:(CGRect)bounds

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The computed drawing rectangle for the route button.

    Discussion

    Use this method to retrieve the bounding rectangle for the route button.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Assigns a button image to the specified control states.

    Declaration

    Swift

    func setRouteButtonImage(_ image: UIImage!, forState state: UIControlState)

    Objective-C

    - (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.

    Import Statement

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.