3

I'm wanting to control the master volume of the iPhone with a UISlider. There is a way of doing it without code and I've forgot how to. So code or within the xib, how do I do this?

Thanks

Plies Neyo
  • 237
  • 1
  • 4
  • 15

2 Answers2

2

You can try the following method: Place it in your XIB.

  1. Open the XIB where you want to place to slider into
  2. Add a UIView to your view
  3. Change the class identity from UIView to MPVolumeView
  4. Change backgroundColor to clear
Panshul
  • 956
  • 1
  • 10
  • 25
  • Thanks works, is there anyway to change the colour of the slider? If it was a normal uislider, you can change the colour through the xib, how would it be done with the mpvolumeview? – Plies Neyo Jul 09 '12 at 17:42
0

Assuming you already have an instance of the MPVolumeView class, you need to search its subviews to find the MPVolumeSlider view:

UISlider *volumeViewSlider;

// Find the MPVolumeSlider
for (UIView *view in [volumeView subviews])
{
   if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) 
   {
       volumeViewSlider = view;
   }
}

[volumeViewSlider setValue: 1.0f animated:YES];
[volumeViewSlider _commitVolumeChange];

Hope this helps you out.

Mathew Varghese
  • 4,527
  • 2
  • 17
  • 26
  • This is good, except that `_commitVolumeChange` is a hack. More information [here](http://stackoverflow.com/questions/3458965/changing-the-volume-without-a-volume-slider-on-an-iphone) and [here](http://blog.stormyprods.com/2009/06/adjusting-iphone-master-volume.html). – JohnK May 18 '13 at 18:49