123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //
- // UIViewController+SPSBDefault.m
- // 我的社保
- //
- // Created by shanp on 2021/4/21.
- //
- #import "UIViewController+SPSBDefault.h"
- #import "SPSBNetworkManager.h"
- #import "UIView+SPSBDefault.h"
- #import <JXHViewMeasure.h>
- #import <objc/runtime.h>
- #import <JXHLayout.h>
- #import "SPSBConstantProfile.h"
- @implementation UIViewController (SPSBDefault)
- - (void)setDefaultViewWithError:(nullable NSError *)error image:(nullable UIImage *)image action:(void(^_Nullable)(void))action {
- if (self.spsb_defaultView) {
- [self.spsb_defaultView removeFromSuperview];
- }
- SPSBNetworkDataDefault type;
- if (error) {
- if (error.code == SPSBNetworkErrorCodeNetwrokMiss) {
- type = SPSBNetworkDataDefaultMissNetwork;
- } else {
- type = SPSBNetworkDataDefaultMissData;
- }
- } else {
- type = SPSBNetworkDataDefaultNoData;
- }
-
- self.spsb_defaultView = [self.view defultViewWithType:type image:image action:action];
-
- [self.view addSubview:self.spsb_defaultView];
- [self.spsb_defaultView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(self.spsb_defaultView.width);
- make.centerY.equalTo(self.view).offset(-jxh_viewHeight(self.view) * SPSBDefaultViewCenterYOffsetProportion);
- }];
-
- }
- - (void)removeDefaultView {
- if (self.spsb_defaultView) {
- [self.spsb_defaultView removeFromSuperview];
- self.spsb_defaultView = nil;
- }
- }
- - (nullable UIView *)spsb_defaultView {
- return objc_getAssociatedObject(self, @selector(setSpsb_defaultView:));
- }
- - (void)setSpsb_defaultView:(UIView *)spsb_defaultView {
- objc_setAssociatedObject(self, _cmd, spsb_defaultView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- @end
|