UIScrollView+Empty.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // UIScrollView+Empty.m
  3. // UIScrollViewEmpty
  4. //
  5. // Created by Jack on 2018/9/5.
  6. // Copyright © 2018年 United Software Applications. All rights reserved.
  7. //
  8. #import "UIScrollView+Empty.h"
  9. #import <objc/runtime.h>
  10. static const char *emptyKey = "emptyKey";
  11. static const float duration = 0.25;
  12. @implementation UIScrollView (Empty)
  13. //- (void)setEmptyDataViewManualsize:(bool)bManualsize
  14. //{
  15. // _emptyDataViewManualsize=bManualsize;
  16. //}
  17. - (void)setEmptyContentView:(RAEmptyDataView *)contentView {
  18. if (contentView) {
  19. UIView *view = objc_getAssociatedObject(self, emptyKey);
  20. if (view) {
  21. [view removeFromSuperview];
  22. }
  23. [self insertSubview:contentView atIndex:0];
  24. [self willChangeValueForKey:@"emptyView"];
  25. objc_setAssociatedObject(self, emptyKey, contentView, OBJC_ASSOCIATION_RETAIN);
  26. [self didChangeValueForKey:@"emptyView"];
  27. }
  28. }
  29. - (RAEmptyDataView *)emptyContentView {
  30. RAEmptyDataView *contentView = objc_getAssociatedObject(self, emptyKey);
  31. if (!contentView) {
  32. contentView = [RAEmptyDataView new];
  33. contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  34. contentView.hidden = YES;
  35. [self setEmptyContentView:contentView];
  36. }
  37. return contentView;
  38. }
  39. - (void)setEmptyView:(UIView *)emptyView {
  40. [self emptyContentView].emptyView = emptyView;
  41. }
  42. - (UIView *)emptyView {
  43. return [self emptyContentView].emptyView;
  44. }
  45. - (void)showEmpty {
  46. UIView *view = [self emptyContentView];
  47. // view.alpha = 0.0f;
  48. view.hidden = NO;
  49. [self bringSubviewToFront:view];
  50. // [UIView animateWithDuration:duration animations:^{
  51. // view.alpha = 1.0f;
  52. // }];
  53. }
  54. - (void)hideEmpty {
  55. UIView *view = [self emptyContentView];
  56. // [UIView animateWithDuration:duration animations:^{
  57. // view.alpha = 0.0f;
  58. // } completion:^(BOOL finished) {
  59. view.hidden = YES;
  60. // }];
  61. [self sendSubviewToBack:view];
  62. }
  63. - (void)setEmptyContentViewBackgroupColor:(UIColor *)color {
  64. self.emptyContentView.backgroundColor = color;
  65. }
  66. @end