CustomLoadingView.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // CustomLoadingView
  3. // JasonDevelop
  4. //
  5. // Created by Jason Lee on 10/23/14.
  6. // Copyright (c) jasondevelop. All rights reserved.
  7. //
  8. #import "CommonUtil.h"
  9. #import "CustomLoadingView.h"
  10. @interface CustomLoadingView () {
  11. UIView *_bgView;
  12. UIImageView* _animatedView;
  13. UIActivityIndicatorView *_indicatorView;
  14. }
  15. @end
  16. @implementation CustomLoadingView
  17. static CustomLoadingView *__loadingView = nil;
  18. + (void)showWithView:(UIView *)superView {
  19. if ([__loadingView superview]) {
  20. return;
  21. }
  22. CGRect screenRect = [UIScreen mainScreen].bounds;
  23. __loadingView = [[CustomLoadingView alloc] initWithFrame:screenRect];
  24. [superView addSubview:__loadingView];
  25. [__loadingView start];
  26. }
  27. + (void)hide {
  28. if (__loadingView) {
  29. [__loadingView stop];
  30. [__loadingView removeFromSuperview];
  31. }
  32. }
  33. - (id)initWithFrame:(CGRect)frame
  34. {
  35. self = [super initWithFrame:frame];
  36. if (self) {
  37. self.backgroundColor = [UIColor clearColor];
  38. _bgView = [[UIView alloc] initWithFrame:self.frame];
  39. _bgView.backgroundColor = [UIColor darkGrayColor];
  40. _bgView.alpha = 0.65;
  41. [self addSubview:_bgView];
  42. CGRect lRect = CGRectMake(0, 0, 90, 90);
  43. _indicatorView = [[UIActivityIndicatorView alloc] initWithFrame:lRect];
  44. _indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
  45. CGRect center = [CommonUtil getCenterPosition:_indicatorView fromContainer:self hasNavigationBar:YES hasTabBar:NO];
  46. _indicatorView.frame = center;
  47. [self addSubview:_indicatorView];
  48. }
  49. return self;
  50. }
  51. - (void)start {
  52. [_indicatorView startAnimating];
  53. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  54. }
  55. - (void)stop {
  56. [_indicatorView stopAnimating];
  57. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
  58. }
  59. @end