When replicating UIAlertView; background is not the same

48 views Asked by At

I'm creating a custom UIAlertView (from a UIView). I'm trying to get the same background effect (when the background view darkens). So I created a new black UIView with .5 opacity, and added it to the background.

The problem is, I have a tab bar. When the black UIView covers the background, it doesn't cover the UIView. Here are 2 images demonstrating my problem:

Standard UIAlertView background:

enter image description here

Custom UIAlertView background

enter image description here

Here is my code creating the background view:

UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
[backgroundView setBackgroundColor:[UIColor blackColor]];
[backgroundView setAlpha:0.5f];
[self.view addSubview:backgroundView];

How can I get the UIView to cover the tab bar?

1

There are 1 answers

0
NeoWang On BEST ANSWER

Try adding backgroundView into self.view.window, not self.view.