UIViewController+TD.m 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // UIViewController+TD.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/10/22.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "UIViewController+TD.h"
  9. #import <objc/runtime.h>
  10. static NSString *statusBar = @"statusBar";
  11. @interface NSObject ()
  12. @end
  13. @implementation UIViewController (TD)
  14. /**
  15. setter方法
  16. */
  17. - (void)setStatusBar:(UIView *)barView {
  18. objc_setAssociatedObject(self, &statusBar, barView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  19. }
  20. /**
  21. getter方法
  22. */
  23. - (UIView *)statusBar {
  24. return objc_getAssociatedObject(self, &statusBar);
  25. }
  26. - (void)loadStatusBarColor:(UIColor *)color {
  27. if (!self.statusBar) {
  28. UIView *barView = [UIView new];
  29. barView.frame = CGRectMake(0, 0, kGXScreenWidth, IS_IPHONEX ? 44 : 20);
  30. [self setStatusBar:barView];
  31. [self.view addSubview:self.statusBar];
  32. }
  33. self.statusBar.backgroundColor = color;
  34. }
  35. @end