UIAlertView装载指示器几乎越位?

时间:2016-04-05 14:02:15

标签: ios objective-c uialertview

我有以下代码:

_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
                                           message:ALERT_MESSAGE_LOADING
                                          delegate:nil
                                 cancelButtonTitle:nil
                                 otherButtonTitles:nil];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];

[_loadingAlert setValue:indicator forKey:@"accessoryView"];
[_loadingAlert show];

结果:

enter image description here

我的目的是显示一个内部有加载指示器的警报视图,但结果是附加的屏幕截图。有人有想法吗?

2 个答案:

答案 0 :(得分:0)

我建议您尝试MBProgressHUD cocoapod,因为它看起来完全符合您的要求,并且将支持iOS 6 +。

https://github.com/jdg/MBProgressHUD

enter image description here

答案 1 :(得分:0)

尝试使用此代码(如@ A-Live建议的那样),您可以调整填充值以在活动指示器的底部添加更多空间。

_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
                                           message:ALERT_MESSAGE_LOADING
                                          delegate:nil
                                 cancelButtonTitle:nil
                                 otherButtonTitles:nil];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
indicator.translatesAutoresizingMaskIntoConstraints = YES;
[indicator startAnimating];

CGFloat padding = 15;
UIView *indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, indicator.frame.size.width, indicator.frame.size.width+padding)];
[indicatorView addSubview:indicator];

[_loadingAlert setValue:indicatorView forKey:@"accessoryView"];
[_loadingAlert show];