- (void)indeterminateExample {
// Show the HUD on the root view (self.view is a scrollable table view and thus not suitable,
// as the HUD would move with the content as we scroll).
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
// Fire off an asynchronous task, giving UIKit the opportunity to redraw with the HUD added to the
// view hierarchy.
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
// Do something useful in the background
[self doSomeWork];
// IMPORTANT - Dispatch back to the main thread. Always access UI
// classes (including MBProgressHUD) on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{
[hud hideAnimated:YES];
});
});
}
- (void)determinateExample {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
// Set the determinate mode to show task progress.
hud.mode = MBProgressHUDModeDeterminate;
hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
// Do something useful in the background and update the HUD periodically.
[self doSomeWorkWithProgress];
dispatch_async(dispatch_get_main_queue(), ^{
[hud hideAnimated:YES];
});
});
}
- (void)customViewExample {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
// Set the custom view mode to show any view.
hud.mode = MBProgressHUDModeCustomView;
// Set a custom image view. We are going to use our logo.
UIImage *image = [[UIImage imageNamed:@"CustomImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
hud.customView = [[UIImageView alloc] initWithImage:image];
// Looks a bit nicer if we make it square.
hud.square = YES;
// Optional label text.
hud.label.text = NSLocalizedString(@"Done", @"HUD done title");
[hud hideAnimated:YES afterDelay:3.f];
}