UITableView+SPSBDefault.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // UITableView+SPSBDefault.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/21.
  6. //
  7. #import "UITableView+SPSBDefault.h"
  8. #import "SPSBNetworkManager.h"
  9. #import "UIView+SPSBDefault.h"
  10. #import <JXHLayout.h>
  11. #import "SPSBConstantProfile.h"
  12. #import <JXHViewMeasure.h>
  13. @implementation UITableView (SPSBDefault)
  14. - (void)setDefaultFootViewWithError:(nullable NSError *)error image:(nullable UIImage *)image height:(CGFloat)height action:(void(^_Nullable)(void))action {
  15. SPSBNetworkDataDefault type;
  16. if (error) {
  17. if (error.code == SPSBNetworkErrorCodeNetwrokMiss) {
  18. type = SPSBNetworkDataDefaultMissNetwork;
  19. } else {
  20. type = SPSBNetworkDataDefaultMissData;
  21. }
  22. } else {
  23. type = SPSBNetworkDataDefaultNoData;
  24. }
  25. UIView *defaultView = [self defultViewWithType:type image:image action:action];
  26. CGFloat defaultViewHeight = [defaultView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height * (SPSBDefaultViewCenterYOffsetProportion * 2 + 1);
  27. if (defaultViewHeight > height) {
  28. height = defaultViewHeight;
  29. }
  30. UIView *footView = [[UIView alloc] initWithFrame:(CGRect){CGPointZero, (CGSize){jxh_viewWidth(self), height}}];
  31. footView.backgroundColor = self.backgroundColor;
  32. [footView addSubview:defaultView];
  33. [defaultView makeConstraints:^(JXHConstraintMaker *make) {
  34. make.leading.and.trailing.equalTo(0);
  35. make.height.equalTo(defaultView.width);
  36. make.centerY.equalTo(footView).offset(-height * SPSBDefaultViewCenterYOffsetProportion);
  37. }];
  38. self.tableFooterView = footView;
  39. }
  40. - (void)removeDefaultFootView {
  41. self.tableFooterView = nil;
  42. }
  43. @end