We're moving away from MBProgressHUD because it's too glitchy in our app, and doesn't have features such as blocking user input or providing a Cancel button.
So, I've attempted to implement Swipesight's How to display activity indicator in center of UIAlertController?, and I ran into improper positioning of the indicator:
It is green because our app's tint is green.
As you can see, it's not in the white rectangle part of the controller, but the grey background. This uses something similar to his "@62Shark" solution:
// in implementation:
@property (nonatomic, strong) UIActivityIndicatorView *spinner;
@property (nonatomic, strong) UIAlertController *alertController;
// in init:
_alertController = [UIAlertController alertControllerWithTitle: @"Loading"
message: nil
preferredStyle: UIAlertControllerStyleAlert];
_spinner = [UIActivityIndicatorView new];
_spinner.translatesAutoresizingMaskIntoConstraints = false;
_spinner.userInteractionEnabled = false;
_spinner.color = [ThemingAssistant tintColor];
_spinner.frame = _alertController.view.bounds;
_spinner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_spinner startAnimating];
[_alertController.view addSubview: _spinner];
// ...
- (void) showOn: (UIViewController *)target
title: (NSString *)title
message: (NSString *)message
canCancel: (BOOL)canCancel
{
self.alertController.title = title;
self.alertController.message = message;
if (canCancel)
{
[self.alertController addAction:[UIAlertAction actionWithTitle: @"Cancel"
style: UIAlertActionStyleCancel
handler: ^(UIAlertAction *name){
[self customDismiss];
}]];
}
NSDictionary *views = @{@"pending" : self.alertController.view,
@"indicator" : self.spinner};
NSArray *constraints =
[NSLayoutConstraint constraintsWithVisualFormat: @"V:[indicator]-(-50)-|"
options: 0
metrics: nil
views: views];
[constraints arrayByAddingObjectsFromArray:
[NSLayoutConstraint constraintsWithVisualFormat: @"H:|[indicator]|"
options: 0
metrics: nil
views: views]];
[target presentViewController: self.alertController
animated: true
completion: nil];
}
Even if this was in the white rectangle, I fear it might run into text (also, when I get it in there, I want it to be in the middle-top, much like MBProgressHUD does), so I'll need a way to reserve some space for it.
So, my question is two-fold: How do I reserve space for a UIActivityIndicatorView
in a UIAlertController
's white rectangle, and then how do I actually place it in there?