3

We're creating an immersive app that needs to have something that acts rather similar to a UIAlertView, but we don't want it to look like a system dialog, we want to use our own graphics. I've got a big chunk of the work done, but there are a few snags I've hit:

  1. How do I make the UIView show up above the status bar (so that I can darken in, like a UIAlertView does)? Is this possible? I've added it to the window, but it still shows up underneath the status bar.

  2. How do I show it partially transparent but have the text still fully opaque? I want it to be shown similar to a UIAlertView in that it should be translucent, but if I set alpha to .8, that also decreases the alpha of subviews. If I only decrease the alpha of the background image, then the buttons appear opaque. If I decrease the alpha of the background image and the buttons, then the buttons don't look like they are embedded in the background image. I would very much like to not have to create a different image for each arrangement of embedded buttons

Edit: I haven't yet found a solution to the status bar issue, but I've noticed that a standard UIAlertView shows up in its own UIWindow, and when I investigated that, I found the windowLevel property:

const UIWindowLevel UIWindowLevelNormal;
const UIWindowLevel UIWindowLevelAlert;
const UIWindowLevel UIWindowLevelStatusBar;

Using my own UIWindow with UIWindowLevelAlert still didn't make it show up above the status bar. I didn't try UIWindowLevelStatusBar.

Ed Marty
  • 39,590
  • 19
  • 103
  • 156
  • It might be too late but you may be able to leverage UIAlertView instead of writing your own class. I did some subview mining to mess around with the buttons and such but I don't recommend doing the same. However you can insert subviews and also change the frame of the UIAlertView, maybe that will meet your needs instead? UIAlertview seems to have a lot of behavior and I wouldn't want to duplicate it, personally. – bpapa Nov 19 '09 at 23:07

6 Answers6

5

You need to create a new Window where you can put your alert view:

UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // you must release the window somewhere, when you do not need it anymore
alertWindow.windowLevel = UIWindowLevelAlert; // puts it above the status bar
alertWindow.backgroundColor = [UIColor clearColor];
UIViewController *alertVC = [[[YourAlertViewController alloc] init] autorelease];
[alertWindow setRootViewController:alertVC];
[alertWindow setHidden:NO];
borisdiakur
  • 10,387
  • 7
  • 68
  • 100
3

Seems an old post but if you hit this page looking for an answer check this out

http://joris.kluivers.nl/iphone-dev/?p=CustomAlert

jermin
  • 31
  • 2
0

If the default behavior of UIAlertView works for you, I'd suggest changing the default look of the dialog. You can for example use the example code from this discussion and provide your own image.

Community
  • 1
  • 1
Markus Müller-Simhofer
  • 3,391
  • 1
  • 28
  • 32
0

How do I make the UIView show up above the status bar (so that I can darken in, like a UIAlertView does)? Is this possible?

I don't think Apple makes this available to a non-UIAlertView subclass of UIView.

UIAlertView is a subclass of UIView. Have you tried subclassing UIAlertView and overriding -drawRect: with your own drawing code?

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • I accept this answer not because subclassing and overriding drawRect: works for me (it doesn't. I've made specific statements that we can't use that class) but because I've resigned myself to the fact that Apple doesn't make this available. – Ed Marty Dec 03 '09 at 17:42
0

What about working around the issue by hiding the status bar when the alert is displayed? That would make it more "alerty" anyway...

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
0

For the opacity issue: have you considered embedding button graphics into the background image, and making the button controls themselves transparent, changing the background image every time a button is pushed down or released?

igul222
  • 8,557
  • 14
  • 52
  • 60
  • If you read the end of my question, notice I said "I would very much like to not have to create a different image for each arrangement of embedded buttons" – Ed Marty Nov 19 '09 at 21:41
  • Ah- sorry, I don't catch that bit. Perhaps keep blank, transparent parts in your background image which line up with the buttons? – igul222 Nov 20 '09 at 05:38
  • again, every time the alignment of the buttons change, I would have to have a different background image. – Ed Marty Nov 22 '09 at 18:19