警报视图在iOS7中显示白色矩形

Pab*_*blo 15 ios ios7

以下代码在iOS 5到6.1中运行良好.我甚至在应用程序中存储了该代码:

-(void)showActivityIndicator
{
    if(!mLoadingView) //
    {
        mLoadingView = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
        mLoadingView.tag = kAlertViewTag;
    }

    [mLoadingView show];
}

- (void)willPresentAlertView:(UIAlertView *)alertView
{
    if (alertView.tag == kAlertViewTag)
    {
        UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        actInd.frame = CGRectMake(128.0f, 45.0f, 25.0f, 25.0f);
        [alertView addSubview:actInd];
        [actInd startAnimating];

        UILabel *l = [[UILabel alloc]init];
        l.text = NSLocalizedString(@"PRODUCT_PURCHASE_INDICATOR_TITLE", @"Please wait...");
        l.font = [UIFont fontWithName:@"Helvetica" size:16];

        float strWidth = [l.text sizeWithFont:l.font].width;
        float frameWidth = alertView.frame.size.width;
        l.frame = CGRectMake((frameWidth - strWidth)/2, -25, 210, 100);

        l.textColor = [UIColor whiteColor];
        l.shadowColor = [UIColor blackColor];
        l.shadowOffset = CGSizeMake(1.0, 1.0);
        l.backgroundColor = [UIColor clearColor];
        [alertView addSubview:l];
    }
}
Run Code Online (Sandbox Code Playgroud)

它将显示没有按钮和活动指示器和标签的警报视图.但是在iOS7中我只能看到白色圆角矩形,没有活动指示.

从iOS 5到7,我可以做些什么?

更新:

为了更具描述性,我正在添加屏幕截图.以下是iOS 5到6.1截图.那里工作得很好.

在此输入图像描述

以下是iOS7.正如您所看到的,即使尺寸更小.看起来它没有完全初始化或什么的.

在此输入图像描述

Jøh*_*røw 20


现在在iOS7中addSubview不可用UIAlertView

UIAlertView班的目的是要原样使用,不支持子类.此类的视图层次结构是私有的,不得修改

作为替代方案,您可以使用SVProgressHUD.


fis*_*ear 20

从iOS 7开始,您可以:

    [alertView setValue:customContentView forKey:@"accessoryView"];
Run Code Online (Sandbox Code Playgroud)

在标准警报视图中获取自定义内容.


Wim*_*guc 19

我不得不很快解决这个问题,因此我构建了一个iOS7 UIAlertView风格的UIView及其动画,可以使用任何自定义内容进行扩展.

可能有其他人可以使用我的解决方案,所以我在Github上提供了整个代码.

在此输入图像描述

此外,如果您希望在以前的OS版本下继续使用UIAlertView,则必须分叉代码.它可能听起来很糟糕,我正在使用以下内容:

float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];

if (sysVer < 7) {
  // your old solution
} else {
  .. // iOS7 dialog code
}
Run Code Online (Sandbox Code Playgroud)

(请注意,这绝不是一个真正的解决方案 - 如果Apple不希望我们将对话用于各种事情,那么我们可能不应该这样做.)

  • @RobCroll肯定,我意外地离开了默认的xcode.随意使用它,尽快更新文件. (3认同)