簡體   English   中英

如何在iOS中以全屏顯示UIAlertView?

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

如何在iOS中將UIAlertView顯示為全屏? 有時候彈出tableview是一個很大的問題。 因此,使用alertview顯示tableview很容易,但不能擴展大小。 為此,如何在iO中全屏顯示alertview?

您不能更改/更改蘋果的默認UIAlertView

而是使用自定義視圖以及它的模仿和行為,您可能想要添加YourCustomAlertView以便:

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

像這樣使用它:

[CustomAlert alertShow];

注意:這只是制作CustomUIAlertView的指南,或者,如果您不想自己搜索一些現成的CustomAlertView ,對不起,我不使用任何書,所以我不推薦。

這只是一個示例,您可以隨意更改任何內容,也許您想添加initWithTitle: message: button:由您自己決定。 和許多其他細節...

干杯! :)

iOS開發人員庫說:

使用此類中定義的屬性和方法來設置警報視圖的標題,消息和委托,並配置按鈕。 如果添加自定義按鈕,則必須設置一個委托。 委托應符合UIAlertViewDelegate協議。 配置警報后,請使用show方法顯示警報視圖。

因此無法修改UIALertView 您需要創建自己的AlertView

只需創建一個視圖並在需要顯示警報時使其可見即可。 github上也有這樣的例子。 您也可以在Cocoapods示例中找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM