Skip to content

Commit

Permalink
update to v1.0.2 ,
Browse files Browse the repository at this point in the history
delete UIViewController category .
  • Loading branch information
Michael Wu committed Apr 12, 2019
1 parent 14c202b commit d2239ce
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 355 deletions.
4 changes: 2 additions & 2 deletions WyhShowEmpty.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "WyhShowEmpty"
s.version = "1.0.1"
s.version = "1.0.2"
s.summary = "Quick to show empty-view in anywhere."

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -79,7 +79,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/XiaoWuTongZhi/WyhShowEmpty.git", :tag => "v1.0.1" }
s.source = { :git => "https://github.com/XiaoWuTongZhi/WyhShowEmpty.git", :tag => "v#{s.version.to_s}" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
13 changes: 4 additions & 9 deletions WyhShowEmpty/UIView+WyhShowEmpty.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

@interface UIView (WyhShowEmpty)

/**
若自定义style,有点击方法时,给外界做处理,若没自定义建议使用
wyh_showEmptyMsg:(NSString *)msg dataCount:(NSUInteger)count Handler:(void(^)())handleBlock
*/
@property (nonatomic, copy) void(^tipHandler)();

/**
自定义style
*/
Expand All @@ -30,7 +24,7 @@
@param msg 提示语
@param count 数据源个数
*/
-(void)wyh_showEmptyMsg:(NSString *)msg dataCount:(NSUInteger)count;
-(void)wyh_showEmptyMsg:(NSString *)msg desc:(NSString *)desc dataCount:(NSUInteger)count;



Expand All @@ -42,7 +36,7 @@
@param hasBtn 是否含有Btn 带btn->YES 点击屏幕->NO
@param handleBlock 刷新方法回调
*/
-(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;

/**
根据数据源个数展示自定义图片的提示视图
Expand All @@ -51,7 +45,7 @@
@param count 数据源个数
@param imageName 图片名称,传nil使用默认图
*/
-(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;


/**
Expand All @@ -63,6 +57,7 @@
@param handleBlock 回调的block
*/
-(void)wyh_showEmptyMsg:(NSString *)msg
desc:(NSString *)desc
dataCount:(NSUInteger)count
customImgName:(NSString *)imageName
imageOragionY:(CGFloat)imageOragionY
Expand Down
185 changes: 95 additions & 90 deletions WyhShowEmpty/UIView+WyhShowEmpty.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ @interface UIView ()

@property (nonatomic, strong) UILabel *tipLabel;

@property (nonatomic, strong) UILabel *descLabel;

@property (nonatomic, strong) UIView *coverView;

@end
Expand All @@ -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];

}

/**
Expand Down Expand Up @@ -165,6 +145,8 @@ -(void)wyh_showWithStyle:(WyhEmptyStyle *)style {
}
}

#pragma mark -

/**
布局coverView
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -250,6 +231,7 @@ -(void)setupSubViewsPositionWithStyle:(WyhEmptyStyle *)style {
[self setupImageViewWithStyle:style];

[self setupTipLabelWithStyle:style];
[self setupDescriptionLabelWithStyle:style];

[self setupButtonWithStyle:style]; /*必须写在setLabel的后面*/

Expand All @@ -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则应去除分割线
Expand All @@ -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;
Expand All @@ -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{
Expand All @@ -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, @"图片数据不能为空");
Expand Down Expand Up @@ -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;
Expand All @@ -407,8 +412,8 @@ -(void)btnClickAction{
// NSLog(@"点击了刷新");
[self removeSubViews]; /*remove一定要放在回调block之前*/

if (self.tipHandler) {
self.tipHandler();
if (self.wyhEmptyStyle.btnClickClosure) {
self.wyhEmptyStyle.btnClickClosure();
}

}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit d2239ce

Please sign in to comment.