-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
delete UIViewController category .
- Loading branch information
Michael Wu
committed
Apr 12, 2019
1 parent
14c202b
commit d2239ce
Showing
16 changed files
with
219 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ @interface UIView () | |
|
||
@property (nonatomic, strong) UILabel *tipLabel; | ||
|
||
@property (nonatomic, strong) UILabel *descLabel; | ||
|
||
@property (nonatomic, strong) UIView *coverView; | ||
|
||
@end | ||
|
@@ -35,105 +37,83 @@ @implementation UIView (WyhShowEmpty) | |
|
||
+(void)load { | ||
|
||
#if DEBUG | ||
NSLog(@"\n\ | ||
WyhShowEmpty 可进行自定义效果展示,只需要重写WyhEmptyStyle的属性\n\ | ||
现已无需设置superView为tableView,默认加在tableView上\n\ | ||
若需求不同,请自行到UIViewController+WyhShowEmpty.m进行修改\n\ | ||
若当你希望调整WyhShowEmpty展示的位置\n\ | ||
请自行调节起始y值位置:\n\ | ||
self.wyhEmptyStyle.imageOragionY(imageOragionY为比例设置)\n\ | ||
如果你在使用中仍然存在问题,请尝试联系我\n\ | ||
简书: http://www.jianshu.com/u/b76e3853ae0b \n\ | ||
QQ邮箱: [email protected] \n\ | ||
"); | ||
/** | ||
* 简书: http://www.jianshu.com/u/b76e3853ae0b | ||
* QQ : [email protected] | ||
*/ | ||
#endif | ||
|
||
} | ||
|
||
-(void)wyh_showEmptyMsg:(NSString *)msg dataCount:(NSUInteger)count { | ||
-(void)wyh_showEmptyMsg:(NSString *)msg desc:(NSString *)desc dataCount:(NSUInteger)count { | ||
|
||
if (!self.wyhEmptyStyle) { | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
wyhStyle.superView = self; | ||
wyhStyle.isOnlyText = YES; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
self.wyhEmptyStyle = wyhStyle; | ||
} | ||
|
||
self.wyhEmptyStyle.tipText = msg; | ||
self.wyhEmptyStyle.dataSourceCount = count; | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
wyhStyle.superView = self; | ||
wyhStyle.isOnlyText = YES; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
wyhStyle.tipText = msg; | ||
wyhStyle.descText = desc; | ||
wyhStyle.dataSourceCount = count; | ||
|
||
[self wyh_showWithStyle:self.wyhEmptyStyle]; | ||
[self wyh_showWithStyle:wyhStyle]; | ||
} | ||
|
||
-(void)wyh_showEmptyMsg:(NSString *)msg dataCount:(NSUInteger)count isHasBtn:(BOOL)hasBtn Handler:(void(^)())handleBlock { | ||
-(void)wyh_showEmptyMsg:(NSString *)msg desc:(NSString *)desc dataCount:(NSUInteger)count isHasBtn:(BOOL)hasBtn Handler:(void(^)())handleBlock { | ||
|
||
if (!self.wyhEmptyStyle) { | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.superView = self; | ||
self.wyhEmptyStyle = wyhStyle; | ||
} | ||
self.wyhEmptyStyle.refreshStyle = hasBtn?RefreshClickOnBtnStyle:RefreshClockOnFullScreenStyle; | ||
self.wyhEmptyStyle.tipText = msg; | ||
self.wyhEmptyStyle.dataSourceCount = count; | ||
self.tipHandler = handleBlock; | ||
|
||
[self wyh_showWithStyle:self.wyhEmptyStyle]; | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.superView = self; | ||
wyhStyle.refreshStyle = hasBtn?RefreshClickOnBtnStyle:RefreshClockOnFullScreenStyle; | ||
wyhStyle.tipText = msg; | ||
wyhStyle.descText = desc; | ||
wyhStyle.dataSourceCount = count; | ||
wyhStyle.btnClickClosure = handleBlock; | ||
|
||
[self wyh_showWithStyle:wyhStyle]; | ||
|
||
} | ||
|
||
-(void)wyh_showEmptyMsg:(NSString *)msg dataCount:(NSUInteger)count customImgName:(NSString *)imageName { | ||
-(void)wyh_showEmptyMsg:(NSString *)msg desc:(NSString *)desc dataCount:(NSUInteger)count customImgName:(NSString *)imageName { | ||
|
||
if (!self.wyhEmptyStyle) { | ||
|
||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
wyhStyle.isOnlyText = NO; | ||
if (imageName) { | ||
wyhStyle.imageConfig.type = ImgTypeName; | ||
wyhStyle.imageConfig.imageData = imageName; | ||
} | ||
wyhStyle.superView = self; | ||
self.wyhEmptyStyle = wyhStyle; | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.refreshStyle = noRefreshStyle; | ||
wyhStyle.isOnlyText = NO; | ||
if (imageName) { | ||
wyhStyle.imageConfig.type = ImgTypeName; | ||
wyhStyle.imageConfig.imageData = imageName; | ||
} | ||
self.wyhEmptyStyle.tipText = msg; | ||
self.wyhEmptyStyle.dataSourceCount = count; | ||
wyhStyle.superView = self; | ||
|
||
wyhStyle.tipText = msg; | ||
wyhStyle.descText = desc; | ||
wyhStyle.dataSourceCount = count; | ||
|
||
[self wyh_showWithStyle:self.wyhEmptyStyle]; | ||
[self wyh_showWithStyle:wyhStyle]; | ||
} | ||
|
||
-(void)wyh_showEmptyMsg:(NSString *)msg | ||
desc:(NSString *)desc | ||
dataCount:(NSUInteger)count | ||
customImgName:(NSString *)imageName | ||
imageOragionY:(CGFloat)imageOragionY | ||
isHasBtn:(BOOL)hasBtn | ||
Handler:(void(^)())handleBlock{ | ||
|
||
if (!self.wyhEmptyStyle) { | ||
WyhEmptyStyle *wyhStyle = [[WyhEmptyStyle alloc]init]; | ||
wyhStyle.superView = self; | ||
self.wyhEmptyStyle = wyhStyle; | ||
} | ||
self.wyhEmptyStyle.refreshStyle = RefreshClockOnFullScreenStyle; | ||
self.wyhEmptyStyle.imageOragionY = imageOragionY; | ||
self.wyhEmptyStyle.tipText = msg; | ||
self.wyhEmptyStyle.imageConfig.imageData = imageName?:self.wyhEmptyStyle.imageConfig.imageData; | ||
self.wyhEmptyStyle.imageConfig.type = ImgTypeName; | ||
self.wyhEmptyStyle.dataSourceCount = count; | ||
WyhEmptyStyle *style = [[WyhEmptyStyle alloc]init]; | ||
style.superView = self; | ||
style.refreshStyle = RefreshClockOnFullScreenStyle; | ||
style.imageOragionY = imageOragionY; | ||
style.tipText = msg; | ||
style.descText = desc; | ||
style.imageConfig.imageData = imageName?:style.imageConfig.imageData; | ||
style.imageConfig.type = ImgTypeName; | ||
style.dataSourceCount = count; | ||
|
||
if (!handleBlock) { | ||
self.wyhEmptyStyle.refreshStyle = noRefreshStyle; | ||
style.refreshStyle = noRefreshStyle; | ||
}else { | ||
self.tipHandler = handleBlock; | ||
self.wyhEmptyStyle.refreshStyle = hasBtn?RefreshClickOnBtnStyle:RefreshClockOnFullScreenStyle; | ||
style.btnClickClosure = handleBlock; | ||
style.refreshStyle = hasBtn?RefreshClickOnBtnStyle:RefreshClockOnFullScreenStyle; | ||
} | ||
[self wyh_showWithStyle:self.wyhEmptyStyle]; | ||
[self wyh_showWithStyle:style]; | ||
|
||
} | ||
|
||
/** | ||
|
@@ -165,6 +145,8 @@ -(void)wyh_showWithStyle:(WyhEmptyStyle *)style { | |
} | ||
} | ||
|
||
#pragma mark - | ||
|
||
/** | ||
布局coverView | ||
|
@@ -202,10 +184,8 @@ -(void)setupCoverViewPostionWithStyle:(WyhEmptyStyle *)style{ | |
} | ||
} | ||
|
||
// Fix masonry-autolayout | ||
[style.superView setNeedsLayout]; | ||
[style.superView layoutIfNeeded]; | ||
|
||
// [style.superView setNeedsLayout]; | ||
// [style.superView layoutIfNeeded]; | ||
superViewWidth = style.superView.wyh_w; | ||
superViewHeight = style.superView.wyh_h; | ||
|
||
|
@@ -234,8 +214,9 @@ -(void)setupSubViewsPositionWithStyle:(WyhEmptyStyle *)style { | |
self.tipButton = nil; | ||
|
||
[self setupTipLabelWithStyle:style]; | ||
[self setupDescriptionLabelWithStyle:style]; | ||
|
||
if (self.tipHandler != nil) { | ||
if (style.btnClickClosure != nil) { | ||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(btnClickAction)]; | ||
tempTapGes = tap; | ||
self.coverView.userInteractionEnabled = YES; | ||
|
@@ -250,6 +231,7 @@ -(void)setupSubViewsPositionWithStyle:(WyhEmptyStyle *)style { | |
[self setupImageViewWithStyle:style]; | ||
|
||
[self setupTipLabelWithStyle:style]; | ||
[self setupDescriptionLabelWithStyle:style]; | ||
|
||
[self setupButtonWithStyle:style]; /*必须写在setLabel的后面*/ | ||
|
||
|
@@ -265,13 +247,15 @@ -(void)setupSubViewsPositionWithStyle:(WyhEmptyStyle *)style { | |
[self setupImageViewWithStyle:style]; | ||
|
||
[self setupTipLabelWithStyle:style]; | ||
[self setupDescriptionLabelWithStyle:style]; | ||
} | ||
|
||
if (style.refreshStyle == noRefreshStyle) { | ||
|
||
[self setupImageViewWithStyle:style]; | ||
|
||
[self setupTipLabelWithStyle:style]; | ||
[self setupDescriptionLabelWithStyle:style]; | ||
} | ||
|
||
//父视图若为tableView则应去除分割线 | ||
|
@@ -293,9 +277,9 @@ -(void)setupTipLabelWithStyle:(WyhEmptyStyle *)style{ | |
tipLabel.font = style.tipFont; | ||
tipLabel.numberOfLines = 0; | ||
tipLabel.textAlignment = NSTextAlignmentCenter; | ||
tipLabel.frame = CGRectMake(0, 0, superViewWidth - 40, 0); | ||
tipLabel.frame = CGRectMake(0, 0, superViewWidth - 80, 0); | ||
[tipLabel sizeToFit]; | ||
NSAssert(superViewHeight>tipLabel.wyh_h, @"设置的文本太长,超出了父视图的高度!"); | ||
NSAssert(superViewHeight>tipLabel.wyh_h, @"设置的标题文本太长,超出了父视图的高度!"); | ||
|
||
[self.coverView addSubview:tipLabel]; | ||
self.tipLabel = tipLabel; | ||
|
@@ -305,7 +289,7 @@ -(void)setupTipLabelWithStyle:(WyhEmptyStyle *)style{ | |
NSAssert(self.tipImageView, @"setupTiplabel必须在setupImage之后,否则获取不到image的frame"); | ||
|
||
CGFloat tipX = (superViewWidth - tipLabel.wyh_w) * 0.5; | ||
CGFloat tipY = self.tipImageView.wyh_bottom + 30; | ||
CGFloat tipY = self.tipImageView.wyh_bottom + 10; | ||
tipLabel.frame = CGRectMake(tipX, tipY, tipLabel.wyh_w, tipLabel.wyh_h); | ||
|
||
}else{ | ||
|
@@ -314,6 +298,27 @@ -(void)setupTipLabelWithStyle:(WyhEmptyStyle *)style{ | |
} | ||
} | ||
|
||
-(void)setupDescriptionLabelWithStyle:(WyhEmptyStyle *)style { | ||
|
||
UILabel *descLabel = [[UILabel alloc]init]; | ||
descLabel.text = !style.descText ? @"" : style.descText; | ||
descLabel.textColor = style.descTextColor; | ||
descLabel.font = style.descFont; | ||
descLabel.numberOfLines = 0; | ||
descLabel.textAlignment = NSTextAlignmentCenter; | ||
descLabel.frame = CGRectMake(0, 0, superViewWidth - 40, 0); | ||
[descLabel sizeToFit]; | ||
NSAssert(superViewHeight>descLabel.wyh_h, @"设置的描述文本太长,超出了父视图的高度!"); | ||
|
||
[self.coverView addSubview:descLabel]; | ||
self.descLabel = descLabel; | ||
|
||
|
||
CGFloat descX = (superViewWidth - descLabel.wyh_w) * 0.5; | ||
CGFloat descY = self.tipLabel.wyh_bottom + 10; | ||
descLabel.frame = CGRectMake(descX, descY, descLabel.wyh_w, descLabel.wyh_h); | ||
} | ||
|
||
-(void)setupImageViewWithStyle:(WyhEmptyStyle *)style{ | ||
|
||
NSAssert(style.imageConfig.imageData, @"图片数据不能为空"); | ||
|
@@ -387,7 +392,7 @@ -(void)setupButtonWithStyle:(WyhEmptyStyle *)style{ | |
btn.wyh_w = btn.wyh_w>style.btnWidth?(btn.wyh_w+10):style.btnWidth; | ||
btn.wyh_h = btn.wyh_h>style.btnHeight?btn.wyh_h:style.btnHeight; | ||
CGFloat btnX = (superViewWidth - btn.wyh_w) * .5f; | ||
CGFloat btnY = CGRectGetMaxY(self.tipLabel.frame) + 20;/*20是一个神奇数字*/ | ||
CGFloat btnY = CGRectGetMaxY(self.descLabel.frame) + 20;/*20是一个神奇数字*/ | ||
btn.wyh_x = btnX; | ||
btn.wyh_y = btnY; | ||
btn.layer.borderColor = style.btnLayerBorderColor.CGColor; | ||
|
@@ -407,8 +412,8 @@ -(void)btnClickAction{ | |
// NSLog(@"点击了刷新"); | ||
[self removeSubViews]; /*remove一定要放在回调block之前*/ | ||
|
||
if (self.tipHandler) { | ||
self.tipHandler(); | ||
if (self.wyhEmptyStyle.btnClickClosure) { | ||
self.wyhEmptyStyle.btnClickClosure(); | ||
} | ||
|
||
} | ||
|
@@ -435,11 +440,19 @@ -(void)removeSubViews{ | |
-(void)setTipLabel:(UILabel *)tipLabel{ | ||
objc_setAssociatedObject(self, &wyh_labelKey, tipLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
} | ||
|
||
-(UILabel *)tipLabel{ | ||
|
||
return objc_getAssociatedObject(self, &wyh_labelKey); | ||
} | ||
|
||
-(void)setDescLabel:(UILabel *)descLabel { | ||
objc_setAssociatedObject(self, @selector(descLabel), descLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
} | ||
|
||
- (UILabel *)descLabel { | ||
return objc_getAssociatedObject(self, _cmd); | ||
} | ||
|
||
#pragma mark - button | ||
-(void)setTipButton:(UIButton *)tipButton{ | ||
objc_setAssociatedObject(self, &wyh_btnKey, tipButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
|
@@ -457,14 +470,6 @@ -(UIImageView *)tipImageView{ | |
return objc_getAssociatedObject(self, &wyh_imageKey); | ||
} | ||
|
||
#pragma mark - block | ||
-(void)setTipHandler:(void (^)())tipHandler{ | ||
objc_setAssociatedObject(self, &wyh_blockKey, tipHandler, OBJC_ASSOCIATION_COPY_NONATOMIC); | ||
} | ||
-(void (^)())tipHandler{ | ||
return objc_getAssociatedObject(self, &wyh_blockKey); | ||
} | ||
|
||
#pragma mark - wyhStyle | ||
-(void)setWyhEmptyStyle:(WyhEmptyStyle *)wyhEmptyStyle{ | ||
objc_setAssociatedObject(self, &wyh_styleKey, wyhEmptyStyle, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
|
Oops, something went wrong.