document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. - (void)indeterminateExample {
  2.     // Show the HUD on the root view (self.view is a scrollable table view and thus not suitable,
  3.     // as the HUD would move with the content as we scroll).
  4.     MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  5.  
  6.     // Fire off an asynchronous task, giving UIKit the opportunity to redraw with the HUD added to the
  7.     // view hierarchy.
  8.     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
  9.  
  10.         // Do something useful in the background
  11.         [self doSomeWork];
  12.  
  13.         // IMPORTANT - Dispatch back to the main thread. Always access UI
  14.         // classes (including MBProgressHUD) on the main thread.
  15.         dispatch_async(dispatch_get_main_queue(), ^{
  16.             [hud hideAnimated:YES];
  17.         });
  18.     });
  19. }
  20.  
  21. - (void)determinateExample {
  22.     MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  23.  
  24.     // Set the determinate mode to show task progress.
  25.     hud.mode = MBProgressHUDModeDeterminate;
  26.     hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");
  27.  
  28.     dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
  29.         // Do something useful in the background and update the HUD periodically.
  30.         [self doSomeWorkWithProgress];
  31.         dispatch_async(dispatch_get_main_queue(), ^{
  32.             [hud hideAnimated:YES];
  33.         });
  34.     });
  35. }
  36.  
  37. - (void)customViewExample {
  38.     MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  39.  
  40.     // Set the custom view mode to show any view.
  41.     hud.mode = MBProgressHUDModeCustomView;
  42.     // Set a custom image view. We are going to use our logo.
  43.     UIImage *image = [[UIImage imageNamed:@"CustomImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  44.     hud.customView = [[UIImageView alloc] initWithImage:image];
  45.     // Looks a bit nicer if we make it square.
  46.     hud.square = YES;
  47.     // Optional label text.
  48.     hud.label.text = NSLocalizedString(@"Done", @"HUD done title");
  49.  
  50.     [hud hideAnimated:YES afterDelay:3.f];
  51. }
');