0

Is it possibe to put an MPVolumeView in a UIAlertView?

I have tried to put it inside of it, but it does not display. It may be the sizeToFit or initWithFrame: part? Is there a way of testing if the MPVolumeView is actually being created?

Here's the code I initialize both the UIAlertView and MPVolumeView with:

UIAlertView *volumeAlert = [[UIAlertView alloc] initWithTitle:@"Volume" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:volumeAlert.bounds];

[volumeAlert addSubview:volumeView]; 

[volumeAlert sizeToFit];

[volumeAlert show];
[volumeAlert release];
[volumeView release];
Emil
  • 7,220
  • 17
  • 76
  • 135
  • Rather than using an `UIAlertView`, I'm just using a simple `UIView` with an transparent image as a "background" for the `MPVolumeView` and some text, and loading that onto the screen, rather than the `UIAlertView`. I am going to keep this question for learning :) – Emil May 19 '10 at 06:42
  • There seems to be some kind of added support for this here: http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MediaPlayerFunctionsReference/Reference/reference.html#//apple_ref/doc/uid/TP40007552 ...but I haven't tried it myself. – iwasrobbed Jul 08 '10 at 19:19

4 Answers4

6

Take a look at MPVolumeSettingsAlertShow()

Displays an alert panel for controlling the system volume.

prendio2
  • 1,885
  • 17
  • 25
1

UIAlertView is a subclass of UIView, and UIView has a convenient addSubview: method. Have you tried that?

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
  • @Emil ok.... so is your code working or not? if it's not, what's happening? what are you expecting to happen? are any errors being logged? you can't just say "here's my code, fix it for me"... – Dave DeLong May 13 '10 at 19:48
  • It is not working, the UIAlert pops up, but there is no volume slider there. Could it be the `initWithFrame:` part that's causing it? Do you know a way of testing if it even creates the volumeView? – Emil May 13 '10 at 19:52
1

I think initing the VolumeView with the VolumeAlert's frame would cause problems. Since VolumeAlert's frame is never being set (before VolumeView's frame is set), you can't depend on it being any size.

ACBurk
  • 4,418
  • 4
  • 34
  • 50
  • What size would I use for this purpose? I am really bad at creating and placing stuff in code/realtime.. – Emil May 19 '10 at 06:34
  • I would just try something like CGRECTMAKE(0,0,100,20) to see if it show up at all to check to see if that is actually the cause. Though if I remember correctly from other things I have read, UIAlertView is not customizable (without private api's or rolling your own version), so this may all be for not. – ACBurk May 19 '10 at 15:51
  • I'll mark this as the accepted answer, because this is the most relevant answer. I do not use this solution afterall, see question. – Emil May 24 '10 at 08:08
0

You might like to check out this recent blog post from Jeff LaMarche, should fill your needs - Custom Alert Views

Ben Williams
  • 4,695
  • 9
  • 47
  • 72