警报视图在 iOS7 中显示白色矩形 [英] Alert view is showing white rectangle in iOS7

查看:18
本文介绍了警报视图在 iOS7 中显示白色矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

The following code works perfectly from iOS 5 to 6.1. I even have applications in store with that code:

-(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];
    }
}

It will show alert view without buttons and with activity indicator and label. However in iOS7 I can see only white rounded rectangle, no activity indicator.

What can I do to have this work from iOS 5 to 7?

Update:

To be more descriptive I'm adding screenshots. The following is iOS 5 to 6.1 screenshot. Works fine there.

The following is iOS7. As you can see even the size is smaller. Looks like it's not fully initialized or something.

解决方案


now addSubview is not available in UIAlertView in iOS7

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified

As an alternative you can use SVProgressHUD.

这篇关于警报视图在 iOS7 中显示白色矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆