Search code examples
iosuialertviewappearance

How to make a UIView that looks exactly like UIAlertView?


I want to show some labels on the screen and I want to make them look exactly like UIAlertView. How can I copy the appearance? Note that I don't care about any of the functionality of the alert view and just want the default appearance as it looks good. Common properties such as backgroundColor on UIAlertView is not set and also the properties of the CALayer don't show anything useful.

Any ideas?


Solution

  • What you're looking for is a Blur Effect. If you're target is iOS 8 and higher, you can use this to create blur views

    UIBlurEffect* blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
        effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
        effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        effectView.frame = self.bounds;
        [self addSubview:effectView];
    

    Apple documentation

    Note that you can use UIBlurEffectStyleExtraLight, UIBlurEffectStyleLight, UIBlurEffectStyleDark.

    If you use a lower version of iOS, you've to use a custom class like FXBlurView.