简体   繁体   中英

UIAlertView loading indicator is almost offside?

I have following code:

_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];

Result:

在此处输入图片说明

My purpose is to display an alertview with loading indicator inside but the result is as attached screenshot. Anyone has idea?

I would suggest you try the MBProgressHUD cocoapod as it appears to do exactly what you want, and will support iOS 6+.

https://github.com/jdg/MBProgressHUD

在此处输入图片说明

Try with this code (as suggested by @A-Live), you can adjust the padding value to add more space at the bottom of the activity indicator.

_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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM