Control Master Volume - iPhone, Cocoa Touch
-
19-06-2021 - |
Question
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
Solution
You can try the following method: Place it in your XIB.
- Open the XIB where you want to place to slider into
- Add a UIView to your view
- Change the class identity from UIView to MPVolumeView
- Change backgroundColor to clear
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow