12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // UIView+SPSBDefault.m
- // 我的社保
- //
- // Created by shanp on 2021/4/21.
- //
- #import "UIView+SPSBDefault.h"
- #import "SPSBUIGeneralHeader.h"
- #import <objc/runtime.h>
- @implementation UIView (SPSBDefault)
- - (UIView *)defultViewWithType:(SPSBNetworkDataDefault)type image:(nullable UIImage *)image action:(void(^_Nullable)(void))action {
- if (!image) {
- switch (type) {
- case SPSBNetworkDataDefaultNoData:
- image = UIImage.new;
- break;
- case SPSBNetworkDataDefaultMissData:
- image = jxh_getImage(loading_failure);
- break;
- case SPSBNetworkDataDefaultMissNetwork:
- image = jxh_getImage(network_error);
-
- default:
- break;
- }
- }
- UIView *defaultView = UIView.new;
-
- UIImageView *icon = [[UIImageView alloc] initWithImage:image];
- [defaultView addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.center.equalTo(0);
- }];
-
- if (action) {
- self.spsb_action = action;
- [defaultView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]];
- }
-
- return defaultView;
- }
- - (void)tapAction {
- if (self.spsb_action) {
- self.spsb_action();
- }
- }
- - (void)setSpsb_action:(void (^)(void))spsb_action {
- objc_setAssociatedObject(self, _cmd, spsb_action, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- - (void (^)(void))spsb_action {
- return objc_getAssociatedObject(self, @selector(setSpsb_action:));
- }
- @end
|