为什么不使用alerviewdelegate方法
- (void)willPresentAlertView:(UIAlertView *)alertView
这样做的好处是我们可以看到警报视图在屏幕上的实际大小,因为 iOS 已经预先计算了这一点,所以不需要幻数 - 或覆盖 Apple 警告的类!
从 iOS7 开始,我记得从 Apple 那里读过一些文件说不要硬编码任何帧大小,而是始终从应用程序计算它们,或者类似的东西?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
在
中拉取对加载栏的引用
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
然后使用
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
记得定义过
#import <objc/runtime.h>
static char myKey;
在类声明的顶部