警报视图在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]; } } 

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

我能做些什么来从iOS 5到这个工作?

更新:

为了更具描述性,我添加了截图。 以下是iOS 5到6.1的截图。 在那里工作很好。

在这里输入图像说明

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

在这里输入图像说明


现在addSubview在iOS7的UIAlertView中不可用

UIAlertView类旨在按原样使用,不支持子类。 这个类的视图层次是私有的,不能被修改

作为替代scheme,您可以使用SVProgressHUD

从iOS 7开始,您可以执行以下操作:

  [alertView setValue:customContentView forKey:@"accessoryView"]; 

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

我不得不快速解决这个问题,因此我已经构build了一个iOS7 UIAlertView风格的UIViewanimation,可以使用任何自定义内容进行扩展。

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

在这里输入图像说明

另外,如果你想继续在以前的操作系统版本下使用UIAlertView,你必须分叉代码。 它可能是一样糟糕,因为它听起来,我使用以下:

 float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; if (sysVer < 7) { // your old solution } else { .. // iOS7 dialog code } 

(请注意,这绝不是一个真正的解决scheme – 如果苹果不希望我们使用各种对话框,那么我们可能不应该这样做。)