MJPhotoLoadingView.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // MJPhotoLoadingView.m
  3. //
  4. // Created by mj on 13-3-4.
  5. // Copyright (c) 2013年 itcast. All rights reserved.
  6. //
  7. #import "MJPhotoLoadingView.h"
  8. #import "MJPhotoBrowser.h"
  9. #import <QuartzCore/QuartzCore.h>
  10. #import "MJPhotoProgressView.h"
  11. @interface MJPhotoLoadingView ()
  12. {
  13. UILabel *_failureLabel;
  14. MJPhotoProgressView *_progressView;
  15. }
  16. @end
  17. @implementation MJPhotoLoadingView
  18. - (void)setFrame:(CGRect)frame
  19. {
  20. [super setFrame:[UIScreen mainScreen].bounds];
  21. }
  22. - (void)showFailure
  23. {
  24. [_progressView removeFromSuperview];
  25. if (_failureLabel == nil) {
  26. _failureLabel = [[UILabel alloc] init];
  27. _failureLabel.bounds = CGRectMake(0, 0, self.bounds.size.width, 44);
  28. _failureLabel.textAlignment = NSTextAlignmentCenter;
  29. _failureLabel.center = self.center;
  30. _failureLabel.text = @"网络不给力,图片下载失败";
  31. _failureLabel.font = [UIFont boldSystemFontOfSize:20];
  32. _failureLabel.textColor = [UIColor whiteColor];
  33. _failureLabel.backgroundColor = [UIColor clearColor];
  34. _failureLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  35. }
  36. [self addSubview:_failureLabel];
  37. }
  38. - (void)showLoading
  39. {
  40. [_failureLabel removeFromSuperview];
  41. if (_progressView == nil) {
  42. _progressView = [[MJPhotoProgressView alloc] init];
  43. _progressView.bounds = CGRectMake( 0, 0, 60, 60);
  44. _progressView.center = self.center;
  45. }
  46. _progressView.progress = kMinProgress;
  47. [self addSubview:_progressView];
  48. }
  49. #pragma mark - customlize method
  50. - (void)setProgress:(float)progress
  51. {
  52. _progress = progress;
  53. _progressView.progress = progress;
  54. if (progress >= 1.0) {
  55. [_progressView removeFromSuperview];
  56. }
  57. }
  58. @end