How can I display an UIAlertView as full screen in iOS?

1.7k views Asked by At

How can I display an UIAlertView as full screen in iOS ? Am very problem some times pop up tableview. So using alertview displaying tableview is easy but it is not expandng size. For that how can dispaly alertview in full screen in iOs ?

2

There are 2 answers

1
0yeoj On BEST ANSWER

You cannot change/alter apples default UIAlertView.

Instead use custom view and mimic and behavior of it, and you might want to add YourCustomAlertView to like:

CustomAlert.h

@interface CustomAlert : NSObject

+ (void)alertShow;

+ (void)alertHide;

@end

CustomAlert.m

@implementation CustomAlert

+ (void)alertShow 
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    UIView *existingView = [window viewWithTag:123456789];

    if (existingView != nil ) // removes existing alert view to avoid multi occurance
    {
        [existingView removeFromSuperview];
    }
    UIView *YourCustomAlertView = [[UIView alloc] initWithFrame:YourFrame];

    YourCustomAlertView.tag = 123456789; // add tag to remove the view later

    // ...

    [window addSubview: YourCustomAlertView]; 
    //this will place your `YourCustomAlertView` to the top most like the default UIAlertView... 

    [UIView animateWithDuration:0.3 animations:^{ [YourCustomAlertView setAlpha:1]; }];
}

+ (void)alertHide
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    UIView * YourCustomAlertView = [window viewWithTag: 123456789];

    [UIView animateWithDuration:0.3 animations:^{

        [YourCustomAlertView setAlpha:0];

    } completion:^(BOOL done){ if (done) { [YourCustomAlertView removeFromSuperview]; } }];
}

@end

Using it like:

[CustomAlert alertShow];

Note: This is just a guide to make CustomUIAlertView or if you dont feel like making your own search for some ready made CustomAlertView, sorry i dont use any so i can't recommend..

This is just an example you can change anything at will, perhaps you like to add initWithTitle: message: button: its up to you. and many other details...

Cheers! :)

0
Gürhan KODALAK On

iOS Developer Library says:

Use the properties and methods defined in this class to set the title, message, and delegate of an alert view and configure the buttons. You must set a delegate if you add custom buttons. The delegate should conform to the UIAlertViewDelegate protocol. Use the show method to display an alert view once it is configured.

so there is no way to modify the UIALertView. You need to create your own AlertView.

Just create a view and make it visible when you need show an alert. Also there are examples on github like this . Also you can find on Cocoapods examples.