How to create a custom UIAlertView

We are creating an immersive application that should have something similar to UIAlertView, but we do not want it to look like a system dialogue, we want to use our own graphics. I have a big chunk of work done, but there are a few snags that I hit:

  • How to make UIView appear above the status bar (so that I can darken, for example UIAlertView)? Is it possible? I added it to the window, but it still appears below the status bar.

  • How do I show it partially transparent, but the text remains completely opaque? I want it to be shown similarly UIAlertViewin the sense that it should be translucent, but if I set the alpha to .8, it also reduces the alpha subview. If I reduce only the alpha of the background image, then the buttons look opaque. If I reduce the alpha of the background image and buttons, the buttons will not look as if they are embedded in the background image. I would really like not to create a different image for each layout of the built-in buttons

Edit: I have not yet found a solution to the problem with the status bar, but I noticed that the standard UIAlertView appears in my own UIWindow, and when I examined this, I found the windowLevel Property:

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

UIWindow UIWindowLevelAlert - . UIWindowLevelStatusBar.

+3
6

UIView ( , UIAlertView)? ?

, Apple UIAlertView UIAlertView.

UIAlertView UIView. UIAlertView -drawRect: ?

0

, :

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];
+5

UIAlertView , . , , .

0

, ? ""...

0

For the problem with opacity: do you think that embedding the image in the background image, and that the control buttons themselves are transparent, changing the background image every time the button is pressed or released?

0
source

Source: https://habr.com/ru/post/1723394/


All Articles