MBHudDemoTVViewController.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // MBHudDemoTVViewController.m
  3. // HudDemoTV
  4. //
  5. // Created by Matej Bukovinski on 17. 07. 16.
  6. // Copyright © 2016 Matej Bukovinski. All rights reserved.
  7. //
  8. #import "MBHudDemoTVViewController.h"
  9. #import "MBProgressHUD.h"
  10. @implementation MBHudDemoTVViewController
  11. - (IBAction)showHud:(UIButton *)sender {
  12. sender.enabled = NO;
  13. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  14. // Set the determinate mode to show task progress.
  15. hud.mode = MBProgressHUDModeDeterminate;
  16. hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");
  17. dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
  18. // Do something useful in the background and update the HUD periodically.
  19. [self doSomeWorkWithProgress];
  20. dispatch_async(dispatch_get_main_queue(), ^{
  21. [hud hideAnimated:YES];
  22. sender.enabled = YES;
  23. });
  24. });
  25. }
  26. - (void)doSomeWorkWithProgress {
  27. // This just increases the progress indicator in a loop.
  28. float progress = 0.0f;
  29. while (progress < 1.0f) {
  30. progress += 0.01f;
  31. dispatch_async(dispatch_get_main_queue(), ^{
  32. // Instead we could have also passed a reference to the HUD
  33. // to the HUD to myProgressTask as a method parameter.
  34. [MBProgressHUD HUDForView:self.view].progress = progress;
  35. });
  36. usleep(50000);
  37. }
  38. }
  39. @end