添加LYEmptyView '~> 0.3.10'
This commit is contained in:
21
Pods/LYEmptyView/LICENSE
generated
Normal file
21
Pods/LYEmptyView/LICENSE
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 yang
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
146
Pods/LYEmptyView/LYEmptyView/LYEmptyBaseView.h
generated
Normal file
146
Pods/LYEmptyView/LYEmptyView/LYEmptyBaseView.h
generated
Normal file
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// LYEmptyBaseView.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2017/5/5.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UIView+LYExtension.h"
|
||||
|
||||
//事件回调
|
||||
typedef void (^LYActionTapBlock)(void);
|
||||
|
||||
@interface LYEmptyBaseView : UIView
|
||||
|
||||
/////////属性传递(可修改)
|
||||
/* image 的优先级大于 imageStr,只有一个有效*/
|
||||
@property (nonatomic, strong)UIImage *image;
|
||||
@property (nonatomic, copy) NSString *imageStr;
|
||||
@property (nonatomic, copy) NSString *titleStr;
|
||||
@property (nonatomic, copy) NSString *detailStr;
|
||||
@property (nonatomic, copy) NSString *btnTitleStr;
|
||||
|
||||
/////////属性传递 (只读)
|
||||
@property (nonatomic,strong,readonly) UIView *contentView;
|
||||
@property (nonatomic, weak, readonly) id actionBtnTarget;
|
||||
@property (nonatomic,assign,readonly) SEL actionBtnAction;
|
||||
@property (nonatomic, copy, readonly) LYActionTapBlock btnClickBlock;
|
||||
@property (nonatomic,strong,readonly) UIView *customView;
|
||||
|
||||
/**
|
||||
emptyView点击事件
|
||||
*/
|
||||
@property (nonatomic, copy) LYActionTapBlock tapEmptyViewBlock;
|
||||
|
||||
|
||||
///初始化配置
|
||||
- (void)prepare;
|
||||
|
||||
///重置Subviews
|
||||
- (void)setupSubviews;
|
||||
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param image 占位图片
|
||||
@param titleStr 标题
|
||||
@param detailStr 详细描述
|
||||
@param btnTitleStr 按钮的名称
|
||||
@param target 响应的对象
|
||||
@param action 按钮点击事件
|
||||
@return 返回一个emptyView
|
||||
*/
|
||||
+ (instancetype)emptyActionViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
target:(id)target
|
||||
action:(SEL)action;
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param image 占位图片
|
||||
@param titleStr 占位描述
|
||||
@param detailStr 详细描述
|
||||
@param btnTitleStr 按钮的名称
|
||||
@param btnClickBlock 按钮点击事件回调
|
||||
@return 返回一个emptyView
|
||||
*/
|
||||
+ (instancetype)emptyActionViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
btnClickBlock:(LYActionTapBlock)btnClickBlock;
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param imageStr 占位图片名称
|
||||
@param titleStr 标题
|
||||
@param detailStr 详细描述
|
||||
@param btnTitleStr 按钮的名称
|
||||
@param target 响应的对象
|
||||
@param action 按钮点击事件
|
||||
@return 返回一个emptyView
|
||||
*/
|
||||
+ (instancetype)emptyActionViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
target:(id)target
|
||||
action:(SEL)action;
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param imageStr 占位图片名称
|
||||
@param titleStr 占位描述
|
||||
@param detailStr 详细描述
|
||||
@param btnTitleStr 按钮的名称
|
||||
@param btnClickBlock 按钮点击事件回调
|
||||
@return 返回一个emptyView
|
||||
*/
|
||||
+ (instancetype)emptyActionViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
btnClickBlock:(LYActionTapBlock)btnClickBlock;
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param image 占位图片
|
||||
@param titleStr 占位描述
|
||||
@param detailStr 详细描述
|
||||
@return 返回一个没有点击事件的emptyView
|
||||
*/
|
||||
+ (instancetype)emptyViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr;
|
||||
|
||||
/**
|
||||
构造方法 - 创建emptyView
|
||||
|
||||
@param imageStr 占位图片名称
|
||||
@param titleStr 占位描述
|
||||
@param detailStr 详细描述
|
||||
@return 返回一个没有点击事件的emptyView
|
||||
*/
|
||||
+ (instancetype)emptyViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr;
|
||||
|
||||
/**
|
||||
构造方法 - 创建一个自定义的emptyView
|
||||
|
||||
@param customView 自定义view
|
||||
@return 返回一个自定义内容的emptyView
|
||||
*/
|
||||
+ (instancetype)emptyViewWithCustomView:(UIView *)customView;
|
||||
|
||||
|
||||
@end
|
||||
212
Pods/LYEmptyView/LYEmptyView/LYEmptyBaseView.m
generated
Normal file
212
Pods/LYEmptyView/LYEmptyView/LYEmptyBaseView.m
generated
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// LYEmptyBaseView.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2017/5/5.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "LYEmptyBaseView.h"
|
||||
|
||||
@interface LYEmptyBaseView ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation LYEmptyBaseView
|
||||
|
||||
#pragma mark - ------------------ Life Cycle ------------------
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self initialize];
|
||||
[self prepare];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize{
|
||||
}
|
||||
|
||||
- (void)prepare{
|
||||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
UIView *view = self.superview;
|
||||
//不是UIView,不做操作
|
||||
if (view && [view isKindOfClass:[UIView class]]){
|
||||
self.ly_width = view.ly_width;
|
||||
self.ly_height = view.ly_height;
|
||||
}
|
||||
|
||||
[self setupSubviews];
|
||||
}
|
||||
|
||||
- (void)setupSubviews{
|
||||
}
|
||||
|
||||
- (void)willMoveToSuperview:(UIView *)newSuperview
|
||||
{
|
||||
[super willMoveToSuperview:newSuperview];
|
||||
|
||||
//不是UIView,不做操作
|
||||
if (newSuperview && ![newSuperview isKindOfClass:[UIView class]]) return;
|
||||
|
||||
if (newSuperview) {
|
||||
self.ly_width = newSuperview.ly_width;
|
||||
self.ly_height = newSuperview.ly_height;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ 实例化 ------------------
|
||||
+ (instancetype)emptyActionViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
target:(id)target
|
||||
action:(SEL)action{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:image imageStr:nil titleStr:titleStr detailStr:detailStr btnTitleStr:btnTitleStr target:target action:action btnClickBlock:nil];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyActionViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
btnClickBlock:(LYActionTapBlock)btnClickBlock{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:image imageStr:nil titleStr:titleStr detailStr:detailStr btnTitleStr:btnTitleStr target:nil action:nil btnClickBlock:btnClickBlock];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyActionViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
target:(id)target
|
||||
action:(SEL)action{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:nil imageStr:imageStr titleStr:titleStr detailStr:detailStr btnTitleStr:btnTitleStr target:target action:action btnClickBlock:nil];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyActionViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr
|
||||
btnTitleStr:(NSString *)btnTitleStr
|
||||
btnClickBlock:(LYActionTapBlock)btnClickBlock{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:nil imageStr:imageStr titleStr:titleStr detailStr:detailStr btnTitleStr:btnTitleStr target:nil action:nil btnClickBlock:btnClickBlock];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyViewWithImage:(UIImage *)image
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:image imageStr:nil titleStr:titleStr detailStr:detailStr btnTitleStr:nil target:nil action:nil btnClickBlock:nil];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyViewWithImageStr:(NSString *)imageStr
|
||||
titleStr:(NSString *)titleStr
|
||||
detailStr:(NSString *)detailStr{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithImage:nil imageStr:imageStr titleStr:titleStr detailStr:detailStr btnTitleStr:nil target:nil action:nil btnClickBlock:nil];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
+ (instancetype)emptyViewWithCustomView:(UIView *)customView{
|
||||
|
||||
LYEmptyBaseView *emptyView = [[self alloc] init];
|
||||
[emptyView creatEmptyViewWithCustomView:customView];
|
||||
|
||||
return emptyView;
|
||||
}
|
||||
|
||||
- (void)creatEmptyViewWithImage:(UIImage *)image imageStr:(NSString *)imageStr titleStr:(NSString *)titleStr detailStr:(NSString *)detailStr btnTitleStr:(NSString *)btnTitleStr target:(id)target action:(SEL)action btnClickBlock:(LYActionTapBlock)btnClickBlock{
|
||||
|
||||
_image = image;
|
||||
_imageStr = imageStr;
|
||||
_titleStr = titleStr;
|
||||
_detailStr = detailStr;
|
||||
_btnTitleStr = btnTitleStr;
|
||||
_actionBtnTarget = target;
|
||||
_actionBtnAction = action;
|
||||
_btnClickBlock = btnClickBlock;
|
||||
|
||||
//内容物背景视图
|
||||
if (!_contentView) {
|
||||
_contentView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[self addSubview:_contentView];
|
||||
}
|
||||
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmptyView:)];
|
||||
[self addGestureRecognizer:tap];
|
||||
}
|
||||
|
||||
- (void)creatEmptyViewWithCustomView:(UIView *)customView{
|
||||
|
||||
//内容物背景视图
|
||||
if (!_contentView) {
|
||||
_contentView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[self addSubview:_contentView];
|
||||
}
|
||||
|
||||
if (!_customView) {
|
||||
[_contentView addSubview:customView];
|
||||
}
|
||||
_customView = customView;
|
||||
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmptyView:)];
|
||||
[self addGestureRecognizer:tap];
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ Event Method ------------------
|
||||
- (void)tapEmptyView:(UITapGestureRecognizer *)tap{
|
||||
if (_tapEmptyViewBlock) {
|
||||
_tapEmptyViewBlock();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ Setter ------------------
|
||||
|
||||
- (void)setImage:(UIImage *)image{
|
||||
_image = image;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
- (void)setImageStr:(NSString *)imageStr{
|
||||
_imageStr = imageStr;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
- (void)setTitleStr:(NSString *)titleStr{
|
||||
_titleStr = titleStr;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
- (void)setDetailStr:(NSString *)detailStr{
|
||||
_detailStr = detailStr;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
- (void)setBtnTitleStr:(NSString *)btnTitleStr{
|
||||
_btnTitleStr = btnTitleStr;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
@end
|
||||
142
Pods/LYEmptyView/LYEmptyView/LYEmptyView.h
generated
Executable file
142
Pods/LYEmptyView/LYEmptyView/LYEmptyView.h
generated
Executable file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// LYEmptyView.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2017/5/10.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "LYEmptyBaseView.h"
|
||||
|
||||
@interface LYEmptyView : LYEmptyBaseView
|
||||
|
||||
/**
|
||||
是否自动显隐EmptyView, default=YES
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL autoShowEmptyView;
|
||||
|
||||
/**
|
||||
占位图是否完全覆盖父视图, default=NO
|
||||
当设置为YES后,占位图的backgroundColor默认为浅白色,可自行设置
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL emptyViewIsCompleteCoverSuperView;
|
||||
|
||||
/**
|
||||
内容物上每个子控件之间的间距 default is 20.f , 这是统一设置的,每个子控件可单独设置
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat subViewMargin;
|
||||
|
||||
/**
|
||||
内容物-垂直方向偏移 (此属性与contentViewY 互斥,只有一个会有效)
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat contentViewOffset;
|
||||
|
||||
/**
|
||||
内容物-Y坐标 (此属性与contentViewOffset 互斥,只有一个会有效)
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat contentViewY;
|
||||
|
||||
/**
|
||||
是否忽略scrollView的contentInset
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL ignoreContentInset;
|
||||
|
||||
|
||||
//-------------------------- image --------------------------//
|
||||
/**
|
||||
图片可设置固定大小 (default=图片实际大小)
|
||||
*/
|
||||
@property (nonatomic, assign) CGSize imageSize;
|
||||
|
||||
|
||||
//-------------------------- titleLab 相关 --------------------------//
|
||||
/**
|
||||
标题字体, 大小default is 16.f
|
||||
*/
|
||||
@property (nonatomic, strong) UIFont *titleLabFont;
|
||||
|
||||
/**
|
||||
标题文字颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *titleLabTextColor;
|
||||
|
||||
/**
|
||||
标题与图片之间的间距 default is @subViewMargin
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat titleLabMargin;
|
||||
|
||||
|
||||
//-------------------------- detailLab 相关 --------------------------//
|
||||
/**
|
||||
详细描述字体,大小default is 14.f
|
||||
*/
|
||||
@property (nonatomic, strong) UIFont *detailLabFont;
|
||||
|
||||
/**
|
||||
详细描述最大行数, default is 2
|
||||
*/
|
||||
@property (nonatomic, assign) NSInteger detailLabMaxLines;
|
||||
|
||||
/**
|
||||
详细描述文字颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *detailLabTextColor;
|
||||
|
||||
/**
|
||||
详细描述文字行间距
|
||||
*/
|
||||
@property (nonatomic, assign) NSInteger detailLabLineSpacing;
|
||||
|
||||
/**
|
||||
详细描述 与 (标题或图片) 之间的间距 default is @subViewMargin
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat detailLabMargin;
|
||||
|
||||
|
||||
//-------------------------- Button 相关 --------------------------//
|
||||
/**
|
||||
按钮字体, 大小default is 14.f
|
||||
*/
|
||||
@property (nonatomic, strong) UIFont *actionBtnFont;
|
||||
/**
|
||||
按钮的高度, default is 40.f
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnHeight;
|
||||
/**
|
||||
按钮的宽度, default is 0.f, (此属性和actionBtnHorizontalMargin只有一个有效,都>0时,此属性优先级大)
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnWidth;
|
||||
/**
|
||||
按钮的水平方向内边距, default is 30.f, (此属性和actionBtnWidth只有一个有效,都>0时,此属性优先级小)
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnHorizontalMargin;
|
||||
/**
|
||||
按钮的圆角大小, default is 0
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnCornerRadius;
|
||||
/**
|
||||
按钮边框border的宽度, default is 0
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnBorderWidth;
|
||||
/**
|
||||
按钮边框颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *actionBtnBorderColor;
|
||||
/**
|
||||
按钮文字颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *actionBtnTitleColor;
|
||||
/**
|
||||
按钮背景颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *actionBtnBackGroundColor;
|
||||
/**
|
||||
按钮背景渐变颜色集合,2个
|
||||
*/
|
||||
@property (nonatomic, strong) NSArray<UIColor *> *actionBtnBackGroundGradientColors;
|
||||
/**
|
||||
按钮 与 (详细描述或标题或图片) 之间的间距 default is @subViewMargin
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat actionBtnMargin;
|
||||
|
||||
@end
|
||||
656
Pods/LYEmptyView/LYEmptyView/LYEmptyView.m
generated
Executable file
656
Pods/LYEmptyView/LYEmptyView/LYEmptyView.m
generated
Executable file
@@ -0,0 +1,656 @@
|
||||
//
|
||||
// LYEmptyView.m
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2017/5/10.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "LYEmptyView.h"
|
||||
|
||||
//每个子控件之间的间距
|
||||
#define kSubViewMargin 20.f
|
||||
|
||||
//描述字体
|
||||
#define kTitleLabFont [UIFont systemFontOfSize:16.f]
|
||||
|
||||
//详细描述字体
|
||||
#define kDetailLabFont [UIFont systemFontOfSize:14.f]
|
||||
|
||||
//按钮字体大小
|
||||
#define kActionBtnFont [UIFont systemFontOfSize:14.f]
|
||||
|
||||
//按钮高度
|
||||
#define kActionBtnHeight 40.f
|
||||
//按钮宽度
|
||||
#define kActionBtnWidth 120.f
|
||||
//水平方向内边距
|
||||
#define kActionBtnHorizontalMargin 30.f
|
||||
|
||||
//背景色
|
||||
#define kBackgroundColor [UIColor colorWithRed:250.f/255.f green:250.f/255.f blue:250.f/255.f alpha:1.f]
|
||||
//黑色
|
||||
#define kBlackColor [UIColor colorWithRed:0.3f green:0.3f blue:0.3f alpha:1.f]
|
||||
//灰色
|
||||
#define kGrayColor [UIColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1.f]
|
||||
|
||||
@interface LYEmptyView ()
|
||||
|
||||
@property (nonatomic, strong) UIImageView *promptImageView;
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UILabel *detailLabel;
|
||||
@property (nonatomic, strong) UIButton *actionButton;
|
||||
@property (nonatomic, strong) UIView *customV;
|
||||
|
||||
@end
|
||||
|
||||
@implementation LYEmptyView
|
||||
{
|
||||
CGFloat contentMaxWidth; //最大宽度
|
||||
CGFloat contentWidth; //内容物宽度
|
||||
CGFloat contentHeight; //内容物高度
|
||||
CGFloat subViweMargin; //内容物上每个子控件之间的间距
|
||||
}
|
||||
|
||||
- (void)initialize{
|
||||
self.actionBtnHeight = 40.f;
|
||||
self.actionBtnWidth = 120.f;
|
||||
self.actionBtnHorizontalMargin = 30.f;
|
||||
self.detailLabMaxLines = 2;
|
||||
}
|
||||
|
||||
- (void)prepare{
|
||||
[super prepare];
|
||||
|
||||
self.autoShowEmptyView = YES; //默认自动显隐
|
||||
self.contentViewY = 1000; //默认值,用来判断是否设置过content的Y值
|
||||
}
|
||||
|
||||
- (void)setupSubviews{
|
||||
[super setupSubviews];
|
||||
|
||||
contentMaxWidth = self.emptyViewIsCompleteCoverSuperView ? self.ly_width : self.ly_width - 30.f;
|
||||
contentWidth = 0;//内容物宽度
|
||||
contentHeight = 0;//内容物高度
|
||||
subViweMargin = self.subViewMargin ? self.subViewMargin : kSubViewMargin;
|
||||
|
||||
//占位图片
|
||||
UIImage *image;
|
||||
if (self.imageStr.length) {
|
||||
image = [UIImage imageNamed:self.imageStr];
|
||||
}
|
||||
if(self.image){
|
||||
[self setupPromptImageView:self.image];
|
||||
}else if (image) {
|
||||
[self setupPromptImageView:image];
|
||||
} else{
|
||||
if (_promptImageView) {
|
||||
[self.promptImageView removeFromSuperview];
|
||||
self.promptImageView = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//标题
|
||||
if (self.titleStr.length) {
|
||||
[self setupTitleLabel:self.titleStr];
|
||||
}else{
|
||||
if (_titleLabel) {
|
||||
[self.titleLabel removeFromSuperview];
|
||||
self.titleLabel = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//详细描述
|
||||
if (self.detailStr.length) {
|
||||
[self setupDetailLabel:self.detailStr];
|
||||
}else{
|
||||
if (_detailLabel) {
|
||||
[self.detailLabel removeFromSuperview];
|
||||
self.detailLabel = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//按钮
|
||||
if (self.btnTitleStr.length) {
|
||||
if (self.actionBtnTarget && self.actionBtnAction) {
|
||||
[self setupActionBtn:self.btnTitleStr target:self.actionBtnTarget action:self.actionBtnAction btnClickBlock:nil];
|
||||
}else if (self.btnClickBlock) {
|
||||
[self setupActionBtn:self.btnTitleStr target:nil action:nil btnClickBlock:self.btnClickBlock];
|
||||
}else{
|
||||
if (_actionButton) {
|
||||
[self.actionButton removeFromSuperview];
|
||||
self.actionButton = nil;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (_actionButton) {
|
||||
[self.actionButton removeFromSuperview];
|
||||
self.actionButton = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//自定义view
|
||||
if (self.customView) {
|
||||
contentWidth = self.customView.ly_width;
|
||||
contentHeight = self.customView.ly_maxY;
|
||||
}
|
||||
|
||||
///设置frame
|
||||
[self setSubViewFrame];
|
||||
}
|
||||
|
||||
- (void)setSubViewFrame{
|
||||
|
||||
//emptyView初始宽高
|
||||
CGFloat originEmptyWidth = self.ly_width;
|
||||
CGFloat originEmptyHeight = self.ly_height;
|
||||
|
||||
CGFloat emptyViewCenterX = originEmptyWidth * 0.5f;
|
||||
CGFloat emptyViewCenterY = originEmptyHeight * 0.5f;
|
||||
|
||||
//不是完全覆盖父视图时,重新设置self的frame(大小为content的大小)
|
||||
if (!self.emptyViewIsCompleteCoverSuperView) {
|
||||
self.ly_size = CGSizeMake(contentWidth, contentHeight);
|
||||
}
|
||||
self.center = CGPointMake(emptyViewCenterX, emptyViewCenterY);
|
||||
|
||||
//设置contentView
|
||||
self.contentView.ly_size = CGSizeMake(contentWidth, contentHeight);
|
||||
if (self.emptyViewIsCompleteCoverSuperView) {
|
||||
self.contentView.center = CGPointMake(emptyViewCenterX, emptyViewCenterY);
|
||||
} else {
|
||||
self.contentView.center = CGPointMake(contentWidth*0.5, contentHeight*0.5);
|
||||
}
|
||||
|
||||
//子控件的centerX设置
|
||||
CGFloat centerX = self.contentView.ly_width * 0.5f;
|
||||
if (self.customView) {
|
||||
self.customView.ly_centerX = centerX;
|
||||
|
||||
}else{
|
||||
_promptImageView.ly_centerX = centerX;
|
||||
_titleLabel.ly_centerX = centerX;
|
||||
_detailLabel.ly_centerX = centerX;
|
||||
_actionButton.ly_centerX = centerX;
|
||||
}
|
||||
|
||||
if (self.contentViewOffset) { //有无设置偏移
|
||||
self.ly_centerY += self.contentViewOffset;
|
||||
|
||||
} else if (self.contentViewY < 1000) { //有无设置Y坐标值
|
||||
self.ly_y = self.contentViewY;
|
||||
|
||||
}
|
||||
|
||||
//是否忽略scrollView的contentInset
|
||||
if (self.ignoreContentInset && [self.superview isKindOfClass:[UIScrollView class]]) {
|
||||
UIScrollView *scrollView = (UIScrollView *)self.superview;
|
||||
self.ly_centerY -= scrollView.contentInset.top;
|
||||
self.ly_centerX -= scrollView.contentInset.left;
|
||||
self.ly_centerY += scrollView.contentInset.bottom;
|
||||
self.ly_centerX += scrollView.contentInset.right;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ Setup View ------------------
|
||||
- (void)setupPromptImageView:(UIImage *)img{
|
||||
|
||||
self.promptImageView.image = img;
|
||||
|
||||
CGFloat imgViewWidth = img.size.width;
|
||||
CGFloat imgViewHeight = img.size.height;
|
||||
|
||||
if (self.imageSize.width && self.imageSize.height) {//设置了宽高大小
|
||||
if (imgViewWidth > imgViewHeight) {//以宽为基准,按比例缩放高度
|
||||
imgViewHeight = (imgViewHeight / imgViewWidth) * self.imageSize.width;
|
||||
imgViewWidth = self.imageSize.width;
|
||||
|
||||
}else{//以高为基准,按比例缩放宽度
|
||||
imgViewWidth = (imgViewWidth / imgViewHeight) * self.imageSize.height;
|
||||
imgViewHeight = self.imageSize.height;
|
||||
}
|
||||
}
|
||||
self.promptImageView.frame = CGRectMake(0, 0, imgViewWidth, imgViewHeight);
|
||||
|
||||
contentWidth = self.promptImageView.ly_size.width;
|
||||
contentHeight = self.promptImageView.ly_maxY;
|
||||
}
|
||||
|
||||
- (void)setupTitleLabel:(NSString *)titleStr{
|
||||
|
||||
UIFont *font = self.titleLabFont.pointSize ? self.titleLabFont : kTitleLabFont;
|
||||
CGFloat fontSize = font.pointSize;
|
||||
UIColor *textColor = self.titleLabTextColor ? self.titleLabTextColor : kBlackColor;
|
||||
CGFloat titleMargin = self.titleLabMargin > 0 ? self.titleLabMargin : (contentHeight == 0 ?: subViweMargin);
|
||||
CGSize size = [self returnTextWidth:titleStr size:CGSizeMake(contentMaxWidth, fontSize + 5) font:font];
|
||||
|
||||
CGFloat width = size.width;
|
||||
CGFloat height = size.height;
|
||||
|
||||
self.titleLabel.frame = CGRectMake(0, contentHeight + titleMargin, width, height);
|
||||
self.titleLabel.font = font;
|
||||
self.titleLabel.text = titleStr;
|
||||
self.titleLabel.textColor = textColor;
|
||||
|
||||
contentWidth = width > contentWidth ? width : contentWidth;
|
||||
contentHeight = self.titleLabel.ly_maxY;
|
||||
}
|
||||
|
||||
- (void)setupDetailLabel:(NSString *)detailStr{
|
||||
|
||||
UIColor *textColor = self.detailLabTextColor ? self.detailLabTextColor : kGrayColor;
|
||||
UIFont *font = self.detailLabFont.pointSize ? self.detailLabFont : kDetailLabFont;
|
||||
CGFloat fontSize = font.pointSize;
|
||||
CGFloat maxLines = self.detailLabMaxLines > 0 ? self.detailLabMaxLines : 1;
|
||||
CGFloat detailMargin = self.detailLabMargin > 0 ? self.detailLabMargin : (contentHeight == 0 ?: subViweMargin);
|
||||
self.detailLabel.font = font;
|
||||
self.detailLabel.textColor = textColor;
|
||||
self.detailLabel.text = detailStr;
|
||||
|
||||
CGFloat width = 0;
|
||||
CGFloat height = 0;
|
||||
|
||||
//设置行高
|
||||
if(self.detailLabLineSpacing){
|
||||
|
||||
CGFloat maxHeight = maxLines * (fontSize + 5) + (maxLines-1) * self.detailLabLineSpacing;
|
||||
|
||||
NSDictionary *dic = [self sizeWithAttributedString:self.detailLabel.text font:font lineSpacing:self.detailLabLineSpacing maxSize:CGSizeMake(contentMaxWidth, maxHeight)];
|
||||
|
||||
NSMutableAttributedString *attStr = dic[@"attributed"];
|
||||
NSValue *sizeValue = dic[@"size"];
|
||||
CGSize size = sizeValue.CGSizeValue;
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
self.detailLabel.attributedText = attStr;
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
CGFloat maxHeight = maxLines * (fontSize + 5);
|
||||
CGSize size = [self returnTextWidth:detailStr size:CGSizeMake(contentMaxWidth, maxHeight) font:font];//计算得出label大小
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
}
|
||||
|
||||
self.detailLabel.frame = CGRectMake(0, contentHeight + detailMargin, width, height);
|
||||
|
||||
contentWidth = width > contentWidth ? width : contentWidth;
|
||||
contentHeight = self.detailLabel.ly_maxY;
|
||||
|
||||
}
|
||||
|
||||
- (void)setupActionBtn:(NSString *)btnTitle target:(id)target action:(SEL)action btnClickBlock:(LYActionTapBlock)btnClickBlock{
|
||||
|
||||
UIFont *font = self.actionBtnFont.pointSize ? self.actionBtnFont : kActionBtnFont;
|
||||
CGFloat fontSize = font.pointSize;
|
||||
UIColor *titleColor = self.actionBtnTitleColor ?: kBlackColor;
|
||||
UIColor *backGColor = self.actionBtnBackGroundColor ?: [UIColor whiteColor];
|
||||
UIColor *borderColor = self.actionBtnBorderColor ?: [UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1.f];
|
||||
CGFloat borderWidth = self.actionBtnBorderWidth ?: 0;
|
||||
CGFloat cornerRadius = self.actionBtnCornerRadius ?: 0;
|
||||
CGFloat width = self.actionBtnWidth;
|
||||
CGFloat horiMargin = self.actionBtnHorizontalMargin;
|
||||
CGFloat height = self.actionBtnHeight;
|
||||
CGSize textSize = [self returnTextWidth:btnTitle size:CGSizeMake(contentMaxWidth, fontSize) font:font];//计算得出title文字内容大小
|
||||
if (height < textSize.height) {
|
||||
height = textSize.height + 4.f;
|
||||
}
|
||||
|
||||
//按钮的宽
|
||||
CGFloat btnWidth = textSize.width;
|
||||
if (width) {
|
||||
btnWidth = width;
|
||||
} else if (horiMargin) {
|
||||
btnWidth = textSize.width + horiMargin * 2.f;
|
||||
}
|
||||
|
||||
//按钮的高
|
||||
CGFloat btnHeight = height;
|
||||
btnWidth = btnWidth > contentMaxWidth ? contentMaxWidth : btnWidth;
|
||||
CGFloat btnMargin = self.actionBtnMargin > 0 ? self.actionBtnMargin : (contentHeight == 0 ?: subViweMargin);
|
||||
|
||||
self.actionButton.frame = CGRectMake(0, contentHeight + btnMargin, btnWidth, btnHeight);
|
||||
[self.actionButton setTitle:btnTitle forState:UIControlStateNormal];
|
||||
self.actionButton.titleLabel.font = font;
|
||||
self.actionButton.backgroundColor = backGColor;
|
||||
if (self.actionBtnBackGroundGradientColors) [self addGradientWithView:self.actionButton gradientColors:self.actionBtnBackGroundGradientColors];
|
||||
[self.actionButton setTitleColor:titleColor forState:UIControlStateNormal];
|
||||
self.actionButton.layer.borderColor = borderColor.CGColor;
|
||||
self.actionButton.layer.borderWidth = borderWidth;
|
||||
self.actionButton.layer.cornerRadius = cornerRadius;
|
||||
|
||||
//添加事件
|
||||
if (target && action) {
|
||||
[self.actionButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.actionButton addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}else if (btnClickBlock) {
|
||||
[self.actionButton addTarget:self action:@selector(actionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
|
||||
contentWidth = btnWidth > contentWidth ? btnWidth : contentWidth;
|
||||
contentHeight = self.actionButton.ly_maxY;
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ Event Method ------------------
|
||||
- (void)actionBtnClick:(UIButton *)sender{
|
||||
if (self.btnClickBlock) {
|
||||
self.btnClickBlock();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ setter ------------------
|
||||
|
||||
- (void)setEmptyViewIsCompleteCoverSuperView:(BOOL)emptyViewIsCompleteCoverSuperView{
|
||||
_emptyViewIsCompleteCoverSuperView = emptyViewIsCompleteCoverSuperView;
|
||||
if (emptyViewIsCompleteCoverSuperView) {
|
||||
if (!self.backgroundColor || [self.backgroundColor isEqual:[UIColor clearColor]]) {
|
||||
self.backgroundColor = kBackgroundColor;
|
||||
}
|
||||
[self setNeedsLayout];
|
||||
}else{
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark 内容物背景视图 相关
|
||||
- (void)setSubViewMargin:(CGFloat)subViewMargin{
|
||||
if (_subViewMargin != subViewMargin) {
|
||||
_subViewMargin = subViewMargin;
|
||||
|
||||
[self reSetupSubviews];
|
||||
}
|
||||
}
|
||||
- (void)setTitleLabMargin:(CGFloat)titleLabMargin{
|
||||
if (_titleLabMargin != titleLabMargin) {
|
||||
_titleLabMargin = titleLabMargin;
|
||||
|
||||
[self reSetupSubviews];
|
||||
}
|
||||
}
|
||||
- (void)setDetailLabMargin:(CGFloat)detailLabMargin{
|
||||
if (_detailLabMargin != detailLabMargin) {
|
||||
_detailLabMargin = detailLabMargin;
|
||||
|
||||
[self reSetupSubviews];
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnMargin:(CGFloat)actionBtnMargin{
|
||||
if (_actionBtnMargin != actionBtnMargin) {
|
||||
_actionBtnMargin = actionBtnMargin;
|
||||
|
||||
[self reSetupSubviews];
|
||||
}
|
||||
}
|
||||
- (void)reSetupSubviews{
|
||||
if (_promptImageView || _titleLabel || _detailLabel || _actionButton || self.customView) {//此判断的意思只是确定self是否已加载完毕
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
- (void)setContentViewOffset:(CGFloat)contentViewOffset{
|
||||
if (_contentViewOffset != contentViewOffset) {
|
||||
_contentViewOffset = contentViewOffset;
|
||||
|
||||
if (_promptImageView || _titleLabel || _detailLabel || _actionButton || self.customView) {
|
||||
self.ly_centerY += self.contentViewOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setContentViewY:(CGFloat)contentViewY{
|
||||
if (_contentViewY != contentViewY) {
|
||||
_contentViewY = contentViewY;
|
||||
|
||||
if (_promptImageView || _titleLabel || _detailLabel || _actionButton || self.customView) {
|
||||
self.ly_y = self.contentViewY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark 提示图Image 相关
|
||||
- (void)setImageSize:(CGSize)imageSize{
|
||||
if (_imageSize.width != imageSize.width || _imageSize.height != imageSize.height) {
|
||||
_imageSize = imageSize;
|
||||
|
||||
if (_promptImageView) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark 描述Label 相关
|
||||
- (void)setTitleLabFont:(UIFont *)titleLabFont{
|
||||
if (_titleLabFont != titleLabFont) {
|
||||
_titleLabFont = titleLabFont;
|
||||
|
||||
if (_titleLabel) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
- (void)setTitleLabTextColor:(UIColor *)titleLabTextColor{
|
||||
if (_titleLabTextColor != titleLabTextColor) {
|
||||
_titleLabTextColor = titleLabTextColor;
|
||||
|
||||
if (_titleLabel) {
|
||||
_titleLabel.textColor = titleLabTextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark 详细描述Label 相关
|
||||
- (void)setDetailLabFont:(UIFont *)detailLabFont{
|
||||
if (_detailLabFont != detailLabFont) {
|
||||
_detailLabFont = detailLabFont;
|
||||
|
||||
if (_detailLabel) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setDetailLabMaxLines:(NSInteger)detailLabMaxLines{
|
||||
if (_detailLabMaxLines != detailLabMaxLines) {
|
||||
_detailLabMaxLines = detailLabMaxLines;
|
||||
|
||||
if (_detailLabel) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setDetailLabTextColor:(UIColor *)detailLabTextColor{
|
||||
if (_detailLabTextColor != detailLabTextColor) {
|
||||
_detailLabTextColor = detailLabTextColor;
|
||||
|
||||
if (_detailLabel) {
|
||||
_detailLabel.textColor = detailLabTextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setDetailLabLineSpacing:(NSInteger)detailLabLineSpacing{
|
||||
if (_detailLabLineSpacing != detailLabLineSpacing) {
|
||||
_detailLabLineSpacing = detailLabLineSpacing;
|
||||
|
||||
if (_detailLabel) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Button 相关
|
||||
//////////大小位置相关-需要重新布局
|
||||
- (void)setActionBtnFont:(UIFont *)actionBtnFont{
|
||||
if (_actionBtnFont != actionBtnFont) {
|
||||
_actionBtnFont = actionBtnFont;
|
||||
|
||||
if (_actionButton) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnHeight:(CGFloat)actionBtnHeight{
|
||||
if (_actionBtnHeight != actionBtnHeight) {
|
||||
_actionBtnHeight = actionBtnHeight;
|
||||
|
||||
if (_actionButton) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnWidth:(CGFloat)actionBtnWidth{
|
||||
if (_actionBtnWidth != actionBtnWidth) {
|
||||
_actionBtnWidth = actionBtnWidth;
|
||||
|
||||
if (_actionButton) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnHorizontalMargin:(CGFloat)actionBtnHorizontalMargin{
|
||||
if (_actionBtnHorizontalMargin != actionBtnHorizontalMargin) {
|
||||
_actionBtnHorizontalMargin = actionBtnHorizontalMargin;
|
||||
|
||||
if (_actionButton) {
|
||||
[self setupSubviews];
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////其他相关-直接赋值
|
||||
- (void)setActionBtnCornerRadius:(CGFloat)actionBtnCornerRadius{
|
||||
if (_actionBtnCornerRadius != actionBtnCornerRadius) {
|
||||
_actionBtnCornerRadius = actionBtnCornerRadius;
|
||||
|
||||
if (_actionButton) {
|
||||
_actionButton.layer.cornerRadius = actionBtnCornerRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnBorderWidth:(CGFloat)actionBtnBorderWidth{
|
||||
if (actionBtnBorderWidth != _actionBtnBorderWidth) {
|
||||
_actionBtnBorderWidth = actionBtnBorderWidth;
|
||||
|
||||
if (_actionButton) {
|
||||
_actionButton.layer.borderWidth = actionBtnBorderWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnBorderColor:(UIColor *)actionBtnBorderColor{
|
||||
if (_actionBtnBorderColor != actionBtnBorderColor) {
|
||||
_actionBtnBorderColor = actionBtnBorderColor;
|
||||
|
||||
if (_actionButton) {
|
||||
_actionButton.layer.borderColor = actionBtnBorderColor.CGColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnTitleColor:(UIColor *)actionBtnTitleColor{
|
||||
if (_actionBtnTitleColor != actionBtnTitleColor) {
|
||||
_actionBtnTitleColor = actionBtnTitleColor;
|
||||
|
||||
if (_actionButton) {
|
||||
[_actionButton setTitleColor:actionBtnTitleColor forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnBackGroundColor:(UIColor *)actionBtnBackGroundColor{
|
||||
if (actionBtnBackGroundColor != _actionBtnBackGroundColor) {
|
||||
_actionBtnBackGroundColor = actionBtnBackGroundColor;
|
||||
|
||||
if (_actionButton) {
|
||||
[_actionButton setBackgroundColor:actionBtnBackGroundColor];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)setActionBtnBackGroundGradientColors:(NSArray<UIColor *> *)actionBtnBackGroundGradientColors
|
||||
{
|
||||
if (actionBtnBackGroundGradientColors.count >= 2) {
|
||||
_actionBtnBackGroundGradientColors = [actionBtnBackGroundGradientColors subarrayWithRange:NSMakeRange(0, 2)];
|
||||
if (_actionButton) {
|
||||
[self addGradientWithView:_actionButton gradientColors:_actionBtnBackGroundGradientColors];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ getter ------------------
|
||||
- (UIImageView *)promptImageView{
|
||||
if (!_promptImageView) {
|
||||
_promptImageView = [[UIImageView alloc] init];
|
||||
_promptImageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[self.contentView addSubview:_promptImageView];
|
||||
}
|
||||
return _promptImageView;
|
||||
}
|
||||
- (UILabel *)titleLabel{
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self.contentView addSubview:_titleLabel];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
- (UILabel *)detailLabel{
|
||||
if (!_detailLabel) {
|
||||
_detailLabel = [[UILabel alloc] init];
|
||||
_detailLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_detailLabel.numberOfLines = 0;
|
||||
[self.contentView addSubview:_detailLabel];
|
||||
}
|
||||
return _detailLabel;
|
||||
}
|
||||
- (UIButton *)actionButton{
|
||||
if (!_actionButton) {
|
||||
_actionButton = [[UIButton alloc] init];
|
||||
_actionButton.layer.masksToBounds = YES;
|
||||
[self.contentView addSubview:_actionButton];
|
||||
}
|
||||
return _actionButton;
|
||||
}
|
||||
|
||||
#pragma mark - ------------------ Help Method ------------------
|
||||
- (CGSize)returnTextWidth:(NSString *)text size:(CGSize)size font:(UIFont *)font{
|
||||
CGSize textSize = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font} context:nil].size;
|
||||
return textSize;
|
||||
}
|
||||
|
||||
- (NSDictionary *)sizeWithAttributedString:(NSString *)string font:(UIFont *)font lineSpacing:(CGFloat)lineSpacing maxSize:(CGSize)maxSize{
|
||||
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
paragraphStyle.lineSpacing = lineSpacing; // 设置行间距
|
||||
paragraphStyle.alignment = NSTextAlignmentCenter;
|
||||
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSParagraphStyleAttributeName: paragraphStyle, NSFontAttributeName:font}];
|
||||
|
||||
CGSize size = [attributedStr boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
|
||||
|
||||
NSDictionary *dic = @{
|
||||
@"attributed":attributedStr,
|
||||
@"size": [NSValue valueWithCGSize:size]
|
||||
};
|
||||
return dic;
|
||||
}
|
||||
|
||||
- (void)addGradientWithView:(UIView *)view gradientColors:(NSArray<UIColor *> *)gradientColors
|
||||
{
|
||||
[view setBackgroundColor:[UIColor clearColor]];
|
||||
|
||||
NSArray *colors = @[(__bridge id)[gradientColors.firstObject CGColor],
|
||||
(__bridge id)[gradientColors.lastObject CGColor]];
|
||||
CAGradientLayer *layer = [CAGradientLayer layer];
|
||||
layer.colors = colors;
|
||||
layer.locations = @[@0.3, @0.5, @1.0];
|
||||
layer.startPoint = CGPointMake(0, 0);
|
||||
layer.endPoint = CGPointMake(1.0, 0);
|
||||
layer.frame = view.bounds;
|
||||
layer.masksToBounds = YES;
|
||||
layer.cornerRadius = view.frame.size.height * 0.5;
|
||||
|
||||
CALayer *firstLayer = self.layer.sublayers.firstObject;
|
||||
if ([firstLayer isKindOfClass:[CAGradientLayer class]]) {
|
||||
[view.layer replaceSublayer:firstLayer with:layer];
|
||||
} else {
|
||||
[view.layer insertSublayer:layer atIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
15
Pods/LYEmptyView/LYEmptyView/LYEmptyViewHeader.h
generated
Normal file
15
Pods/LYEmptyView/LYEmptyView/LYEmptyViewHeader.h
generated
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// LYEmptyViewHeader.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by 李阳 on 2017/5/11.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef LYEmptyViewHeader_h
|
||||
#define LYEmptyViewHeader_h
|
||||
|
||||
#import "LYEmptyView.h"
|
||||
#import "UIView+Empty.h"
|
||||
|
||||
#endif /* LYEmptyViewHeader_h */
|
||||
54
Pods/LYEmptyView/LYEmptyView/UIView+Empty.h
generated
Normal file
54
Pods/LYEmptyView/LYEmptyView/UIView+Empty.h
generated
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// UIView+Empty.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2018/5/10.
|
||||
// Copyright © 2018年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class LYEmptyView;
|
||||
|
||||
@interface UIView (Empty)
|
||||
|
||||
/**
|
||||
空页面占位图控件
|
||||
*/
|
||||
@property (nonatomic, strong) LYEmptyView *ly_emptyView;
|
||||
|
||||
///////////////////////
|
||||
///////////////////////
|
||||
//使用下面的四个方法请将EmptyView的autoShowEmptyView值置为NO,关闭自动显隐,以保证不受自动显隐的影响
|
||||
///////////////////////
|
||||
///////////////////////
|
||||
|
||||
/**
|
||||
一般用于开始请求网络时调用,ly_startLoading调用时会暂时隐藏emptyView
|
||||
当调用ly_endLoading方法时,ly_endLoading方法内部会根据当前的tableView/collectionView的
|
||||
DataSource来自动判断是否显示emptyView
|
||||
*/
|
||||
- (void)ly_startLoading;
|
||||
|
||||
/**
|
||||
在想要刷新emptyView状态时调用
|
||||
注意:ly_endLoading 的调用时机,有刷新UI的地方一定要等到刷新UI的方法之后调用,
|
||||
因为只有刷新了UI,view的DataSource才会更新,故调用此方法才能正确判断是否有内容。
|
||||
*/
|
||||
- (void)ly_endLoading;
|
||||
|
||||
|
||||
//调用下面两个手动显隐的方法,不受DataSource的影响,单独设置显示与隐藏(前提是关闭autoShowEmptyView)
|
||||
|
||||
/**
|
||||
手动调用显示emptyView
|
||||
*/
|
||||
- (void)ly_showEmptyView;
|
||||
|
||||
/**
|
||||
手动调用隐藏emptyView
|
||||
*/
|
||||
- (void)ly_hideEmptyView;
|
||||
|
||||
@end
|
||||
|
||||
224
Pods/LYEmptyView/LYEmptyView/UIView+Empty.m
generated
Normal file
224
Pods/LYEmptyView/LYEmptyView/UIView+Empty.m
generated
Normal file
@@ -0,0 +1,224 @@
|
||||
//
|
||||
// UIView+Empty.m
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by liyang on 2018/5/10.
|
||||
// Copyright © 2018年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIView+Empty.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "LYEmptyView.h"
|
||||
|
||||
#pragma mark - ------------------ UIView ------------------
|
||||
|
||||
@implementation UIView (Empty)
|
||||
|
||||
+ (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2
|
||||
{
|
||||
method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2));
|
||||
}
|
||||
|
||||
#pragma mark - Setter/Getter
|
||||
|
||||
static char kEmptyViewKey;
|
||||
- (void)setLy_emptyView:(LYEmptyView *)ly_emptyView{
|
||||
if (ly_emptyView != self.ly_emptyView) {
|
||||
|
||||
objc_setAssociatedObject(self, &kEmptyViewKey, ly_emptyView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
|
||||
for (UIView *view in self.subviews) {
|
||||
if ([view isKindOfClass:[LYEmptyView class]]) {
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
}
|
||||
[self addSubview:self.ly_emptyView];
|
||||
|
||||
if ([self isKindOfClass:[UITableView class]] || [self isKindOfClass:[UICollectionView class]]) {
|
||||
[self getDataAndSet]; // 添加时根据DataSource去决定显隐
|
||||
} else {
|
||||
self.ly_emptyView.hidden = YES;// 添加时默认隐藏
|
||||
}
|
||||
}
|
||||
}
|
||||
- (LYEmptyView *)ly_emptyView{
|
||||
return objc_getAssociatedObject(self, &kEmptyViewKey);
|
||||
}
|
||||
|
||||
#pragma mark - Private Method (UITableView、UICollectionView有效)
|
||||
- (NSInteger)totalDataCount
|
||||
{
|
||||
NSInteger totalCount = 0;
|
||||
if ([self isKindOfClass:[UITableView class]]) {
|
||||
UITableView *tableView = (UITableView *)self;
|
||||
|
||||
for (NSInteger section = 0; section < tableView.numberOfSections; section++) {
|
||||
totalCount += [tableView numberOfRowsInSection:section];
|
||||
}
|
||||
} else if ([self isKindOfClass:[UICollectionView class]]) {
|
||||
UICollectionView *collectionView = (UICollectionView *)self;
|
||||
|
||||
for (NSInteger section = 0; section < collectionView.numberOfSections; section++) {
|
||||
totalCount += [collectionView numberOfItemsInSection:section];
|
||||
}
|
||||
}
|
||||
return totalCount;
|
||||
}
|
||||
- (void)getDataAndSet{
|
||||
//没有设置emptyView的,直接返回
|
||||
if (!self.ly_emptyView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ([self totalDataCount] == 0) {
|
||||
[self show];
|
||||
}else{
|
||||
[self hide];
|
||||
}
|
||||
}
|
||||
- (void)show{
|
||||
//当不自动显隐时,内部自动调用show方法时也不要去显示,要显示的话只有手动去调用 ly_showEmptyView
|
||||
if (!self.ly_emptyView.autoShowEmptyView) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self ly_showEmptyView];
|
||||
}
|
||||
- (void)hide{
|
||||
//当不自动显隐时,内部自动调用hide方法时也不要去隐藏,要隐藏的话只有手动去调用 ly_hideEmptyView
|
||||
if (!self.ly_emptyView.autoShowEmptyView) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self ly_hideEmptyView];
|
||||
}
|
||||
|
||||
#pragma mark - Public Method
|
||||
- (void)ly_showEmptyView{
|
||||
|
||||
NSAssert(![self isKindOfClass:[LYEmptyView class]], @"LYEmptyView及其子类不能调用ly_showEmptyView方法");
|
||||
|
||||
self.ly_emptyView.hidden = NO;
|
||||
|
||||
//让 emptyBGView 始终保持在最上层
|
||||
[self bringSubviewToFront:self.ly_emptyView];
|
||||
}
|
||||
- (void)ly_hideEmptyView{
|
||||
NSAssert(![self isKindOfClass:[LYEmptyView class]], @"LYEmptyView及其子类不能调用ly_hideEmptyView方法");
|
||||
self.ly_emptyView.hidden = YES;
|
||||
}
|
||||
- (void)ly_startLoading{
|
||||
NSAssert(![self isKindOfClass:[LYEmptyView class]], @"LYEmptyView及其子类不能调用ly_startLoading方法");
|
||||
self.ly_emptyView.hidden = YES;
|
||||
}
|
||||
- (void)ly_endLoading{
|
||||
NSAssert(![self isKindOfClass:[LYEmptyView class]], @"LYEmptyView及其子类不能调用ly_endLoading方法");
|
||||
self.ly_emptyView.hidden = [self totalDataCount];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - ------------------ UITableView ------------------
|
||||
|
||||
@implementation UITableView (Empty)
|
||||
+ (void)load{
|
||||
|
||||
[self exchangeInstanceMethod1:@selector(reloadData) method2:@selector(ly_reloadData)];
|
||||
|
||||
///section
|
||||
[self exchangeInstanceMethod1:@selector(insertSections:withRowAnimation:) method2:@selector(ly_insertSections:withRowAnimation:)];
|
||||
[self exchangeInstanceMethod1:@selector(deleteSections:withRowAnimation:) method2:@selector(ly_deleteSections:withRowAnimation:)];
|
||||
[self exchangeInstanceMethod1:@selector(reloadSections:withRowAnimation:) method2:@selector(ly_reloadSections:withRowAnimation:)];
|
||||
|
||||
///row
|
||||
[self exchangeInstanceMethod1:@selector(insertRowsAtIndexPaths:withRowAnimation:) method2:@selector(ly_insertRowsAtIndexPaths:withRowAnimation:)];
|
||||
[self exchangeInstanceMethod1:@selector(deleteRowsAtIndexPaths:withRowAnimation:) method2:@selector(ly_deleteRowsAtIndexPaths:withRowAnimation:)];
|
||||
[self exchangeInstanceMethod1:@selector(reloadRowsAtIndexPaths:withRowAnimation:) method2:@selector(ly_reloadRowsAtIndexPaths:withRowAnimation:)];
|
||||
}
|
||||
- (void)ly_reloadData{
|
||||
[self ly_reloadData];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
///section
|
||||
- (void)ly_insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_insertSections:sections withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_deleteSections:sections withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_reloadSections:sections withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
|
||||
///row
|
||||
- (void)ly_insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{
|
||||
[self ly_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - ------------------ UICollectionView ------------------
|
||||
|
||||
@implementation UICollectionView (Empty)
|
||||
|
||||
+ (void)load{
|
||||
|
||||
[self exchangeInstanceMethod1:@selector(reloadData) method2:@selector(ly_reloadData)];
|
||||
|
||||
///section
|
||||
[self exchangeInstanceMethod1:@selector(insertSections:) method2:@selector(ly_insertSections:)];
|
||||
[self exchangeInstanceMethod1:@selector(deleteSections:) method2:@selector(ly_deleteSections:)];
|
||||
[self exchangeInstanceMethod1:@selector(reloadSections:) method2:@selector(ly_reloadSections:)];
|
||||
|
||||
///item
|
||||
[self exchangeInstanceMethod1:@selector(insertItemsAtIndexPaths:) method2:@selector(ly_insertItemsAtIndexPaths:)];
|
||||
[self exchangeInstanceMethod1:@selector(deleteItemsAtIndexPaths:) method2:@selector(ly_deleteItemsAtIndexPaths:)];
|
||||
[self exchangeInstanceMethod1:@selector(reloadItemsAtIndexPaths:) method2:@selector(ly_reloadItemsAtIndexPaths:)];
|
||||
|
||||
}
|
||||
- (void)ly_reloadData{
|
||||
[self ly_reloadData];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
///section
|
||||
- (void)ly_insertSections:(NSIndexSet *)sections{
|
||||
[self ly_insertSections:sections];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_deleteSections:(NSIndexSet *)sections{
|
||||
[self ly_deleteSections:sections];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_reloadSections:(NSIndexSet *)sections{
|
||||
[self ly_reloadSections:sections];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
|
||||
///item
|
||||
- (void)ly_insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
|
||||
[self ly_insertItemsAtIndexPaths:indexPaths];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
|
||||
[self ly_deleteItemsAtIndexPaths:indexPaths];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
- (void)ly_reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
|
||||
[self ly_reloadItemsAtIndexPaths:indexPaths];
|
||||
[self getDataAndSet];
|
||||
}
|
||||
@end
|
||||
|
||||
26
Pods/LYEmptyView/LYEmptyView/UIView+LYExtension.h
generated
Normal file
26
Pods/LYEmptyView/LYEmptyView/UIView+LYExtension.h
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// UIView+LYExtension.h
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by 李阳 on 2017/5/12.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface UIView (LYExtension)
|
||||
|
||||
@property (nonatomic, assign) CGFloat ly_x;
|
||||
@property (nonatomic, assign) CGFloat ly_y;
|
||||
@property (nonatomic, assign) CGFloat ly_width;
|
||||
@property (nonatomic, assign) CGFloat ly_height;
|
||||
@property (nonatomic, assign) CGFloat ly_centerX;
|
||||
@property (nonatomic, assign) CGFloat ly_centerY;
|
||||
@property (nonatomic, assign) CGSize ly_size;
|
||||
@property (nonatomic, assign) CGPoint ly_origin;
|
||||
@property (nonatomic, assign, readonly) CGFloat ly_maxX;
|
||||
@property (nonatomic, assign, readonly) CGFloat ly_maxY;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
108
Pods/LYEmptyView/LYEmptyView/UIView+LYExtension.m
generated
Normal file
108
Pods/LYEmptyView/LYEmptyView/UIView+LYExtension.m
generated
Normal file
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// UIView+LYExtension.m
|
||||
// LYEmptyViewDemo
|
||||
//
|
||||
// Created by 李阳 on 2017/5/12.
|
||||
// Copyright © 2017年 liyang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIView+LYExtension.h"
|
||||
|
||||
@implementation UIView (LYExtension)
|
||||
|
||||
- (void)setLy_x:(CGFloat)ly_x{
|
||||
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.x = ly_x;
|
||||
self.frame = frame;
|
||||
}
|
||||
- (CGFloat)ly_x
|
||||
{
|
||||
return self.frame.origin.x;
|
||||
}
|
||||
|
||||
- (void)setLy_y:(CGFloat)ly_y{
|
||||
|
||||
CGRect frame = self.frame;
|
||||
frame.origin.y = ly_y;
|
||||
self.frame = frame;
|
||||
}
|
||||
- (CGFloat)ly_y
|
||||
{
|
||||
return self.frame.origin.y;
|
||||
}
|
||||
|
||||
- (void)setLy_centerX:(CGFloat)ly_centerX{
|
||||
CGPoint center = self.center;
|
||||
center.x = ly_centerX;
|
||||
self.center = center;
|
||||
}
|
||||
- (CGFloat)ly_centerX
|
||||
{
|
||||
return self.center.x;
|
||||
}
|
||||
|
||||
- (void)setLy_centerY:(CGFloat)ly_centerY
|
||||
{
|
||||
CGPoint center = self.center;
|
||||
center.y = ly_centerY;
|
||||
self.center = center;
|
||||
}
|
||||
- (CGFloat)ly_centerY
|
||||
{
|
||||
return self.center.y;
|
||||
}
|
||||
|
||||
- (void)setLy_width:(CGFloat)ly_width
|
||||
{
|
||||
CGRect frame = self.frame;
|
||||
frame.size.width = ly_width;
|
||||
self.frame = frame;
|
||||
}
|
||||
- (CGFloat)ly_width
|
||||
{
|
||||
return self.frame.size.width;
|
||||
}
|
||||
|
||||
- (void)setLy_height:(CGFloat)ly_height
|
||||
{
|
||||
CGRect frame = self.frame;
|
||||
frame.size.height = ly_height;
|
||||
self.frame = frame;
|
||||
}
|
||||
- (CGFloat)ly_height
|
||||
{
|
||||
return self.frame.size.height;
|
||||
}
|
||||
|
||||
- (void)setLy_size:(CGSize)ly_size
|
||||
{
|
||||
CGRect frame = self.frame;
|
||||
frame.size = ly_size;
|
||||
self.frame = frame;
|
||||
}
|
||||
- (CGSize)ly_size
|
||||
{
|
||||
return self.frame.size;
|
||||
}
|
||||
|
||||
- (void)setLy_origin:(CGPoint)ly_origin
|
||||
{
|
||||
CGRect frame = self.frame;
|
||||
frame.origin = ly_origin;
|
||||
self.frame = frame;
|
||||
}
|
||||
|
||||
- (CGPoint)ly_origin
|
||||
{
|
||||
return self.frame.origin;
|
||||
}
|
||||
- (CGFloat)ly_maxX{
|
||||
return self.frame.origin.x + self.frame.size.width;
|
||||
}
|
||||
- (CGFloat)ly_maxY{
|
||||
return self.frame.origin.y + self.frame.size.height;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
297
Pods/LYEmptyView/README.md
generated
Normal file
297
Pods/LYEmptyView/README.md
generated
Normal file
@@ -0,0 +1,297 @@
|
||||
# LYEmptyView
|
||||
不需要遵循协议,不需要设置代理,不需要实现代理方法,只需这一句代码,就可为一个UITableViwe/UICollectionView集成空白页面占位图。<br>`self.tableView.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];`
|
||||
|
||||
#### 注意点:
|
||||
#### 1.除UITableViwe/UICollectionView外,这些View(包括UIScrollView)没有DataSource,代码层面无法判断有无数据,需手动管理显示隐藏,调用示例请移步示例8
|
||||
|
||||
| 特点 | 描述 |
|
||||
| ---------- | -----------|
|
||||
| 与项目完全解耦 | 在需要集成的界面中加入一行代码即可集成,与原代码没有一点耦合度 |
|
||||
| 0学习成本 | 无需关心视图的显示隐藏时机,只需加入一行代码即可,框架监听了系统刷新UI的方法,其内部计算后自动进行显示隐藏 |
|
||||
| 调用简单 | 利用分类+runtime,使调用非常简便 |
|
||||
| 高度自定义 | 利用继承特性,可对框架进行二次封装,使自定义更简便 |
|
||||
| 支持全部的刷新方法 | reload...、insert...、delete...等方法。你的项目中调用这些刷新方法时,该框架都会自动根据DataSource自动进行计算判断是否显示emptyView |
|
||||
|
||||
# 目录
|
||||
* [一、效果展示](#效果展示)<br>
|
||||
* [二、集成方式](#集成方式)<br>
|
||||
* [三、使用参考示例](#使用参考示例)<br>
|
||||
* [1.一行代码集成空内容视图](#一行代码集成空内容视图)<br>
|
||||
* [2.自由选择空内容元素](#自由选择空内容元素)<br>
|
||||
* [3.自定义空内容元素](#自定义空内容元素)<br>
|
||||
* [4.自定义元素的UI样式](#自定义元素的UI样式)<br>
|
||||
* [5.二次封装](#二次封装)<br>
|
||||
* [6.延迟显示emptyView](#延迟显示emptyView)<br>
|
||||
* [7.特殊需求,手动控制emptyView的显示隐藏](#特殊需求,手动控制emptyView的显示隐藏)<br>
|
||||
* [8.普通view调用示例](#普通view调用示例)<br>
|
||||
* [9.占位图完全覆盖父视图](#占位图完全覆盖父视图)<br>
|
||||
|
||||
## <a id="效果展示"></a>一、效果展示
|
||||
|
||||

|
||||
|
||||
## <a id="集成方式"></a>二、集成方式
|
||||
|
||||
1.Cocoapods方式集成: `pod 'LYEmptyView'`<br>
|
||||
使用时导入头文件 `#import <LYEmptyView/LYEmptyViewHeader.h>`
|
||||
<br><br>
|
||||
2.手动下载集成: 将LYEmptyView文件夹,导入你的工程<br>
|
||||
使用时导入头文件:`#import "LYEmptyViewHeader.h"`
|
||||
|
||||
|
||||
## <a id="使用参考示例"></a>三、使用参考示例
|
||||
|
||||
### <a id="一行代码集成空内容视图"></a>1.一行代码集成空内容视图
|
||||
|
||||
```Objective-C
|
||||
//框架方法
|
||||
self.tableView.ly_emptyView = [LYEmptyView emptyViewWithImageStr:@"noData"
|
||||
titleStr:@"暂无数据,点击重新加载"
|
||||
detailStr:@""];
|
||||
```
|
||||
|
||||
PS:可对库进行二次封装,调用更简洁(二次封装方法在下面的示例5中会讲到)
|
||||
```Objective-C
|
||||
//二次封装方法,调用简洁
|
||||
self.tableView.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];
|
||||
```
|
||||
|
||||
完全低耦合,在你的项目中加入这一行代码就可集成<br>
|
||||
不管项目中是reloadData方法刷UI还是insert、delete等方式刷UI,不需做其他任何操作,只需这一行代码就可实现以下效果
|
||||
|
||||

|
||||
|
||||
### <a id="自由选择空内容元素"></a>2.自由选择空内容元素
|
||||
```Objective-C
|
||||
交互事件可选择SEL或block方式
|
||||
self.tableView.ly_emptyView = [LYEmptyView emptyActionViewWithImageStr:@"noData"
|
||||
titleStr:@"无数据"
|
||||
detailStr:@"请稍后再试!"
|
||||
btnTitleStr:@"重新加载"
|
||||
target:target
|
||||
action:action];
|
||||
self.tableView.ly_emptyView = [LYEmptyView emptyActionViewWithImageStr:@"noData"
|
||||
titleStr:@""
|
||||
detailStr:@""
|
||||
btnTitleStr:@""
|
||||
btnClickBlock:^{}];
|
||||
// imageStr : 占位图片
|
||||
// titleStr : 标题
|
||||
// detailStr : 详细描述
|
||||
// btnTitleStr : 按钮标题
|
||||
```
|
||||
框架提供四个元素,传入相应元素的字符串即可显示对应元素(按钮的显示前提是传入target,action或btnClickBlock)
|
||||
可根据项目需求,自由进行组合,如下只展示了部分组合效果
|
||||
|
||||

|
||||
|
||||
### <a id="自定义空内容元素"></a>3.自定义空内容元素
|
||||
特殊情况下,如果空内容状态布局不满足需求时,可进行自定义<br>
|
||||
通过方法` + (instancetype)emptyViewWithCustomView:(UIView *)customView;`<br>
|
||||
传入一个View 即可创建一个自定义的emptyView
|
||||
```Objective-C
|
||||
self.tableView.ly_emptyView = [LYEmptyView emptyViewWithCustomView:customView];
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
### <a id="自定义元素的UI样式"></a>4.自定义元素的UI样式
|
||||
这里自定义UI样式需要很多代码,别担心,在示例5中会讲解二次封装的方式,封装后调用时就只需要一行代码了 ^_^
|
||||
```Objective-C
|
||||
//初始化一个emptyView
|
||||
LYEmptyView *emptyView = [LYEmptyView emptyActionViewWithImageStr:@"noData"
|
||||
titleStr:@"无数据"
|
||||
detailStr:@"请稍后再试!"
|
||||
btnTitleStr:@"重新加载"
|
||||
btnClickBlock:^{}];
|
||||
//元素竖直方向的间距
|
||||
emptyView.subViewMargin = 20.f;
|
||||
//标题颜色
|
||||
emptyView.titleLabTextColor = MainColor(90, 180, 160);
|
||||
//描述字体
|
||||
emptyView.detailLabFont = [UIFont systemFontOfSize:17];
|
||||
//按钮背景色
|
||||
emptyView.actionBtnBackGroundColor = MainColor(90, 180, 160);
|
||||
|
||||
//设置空内容占位图
|
||||
self.tableView.ly_emptyView = emptyView;
|
||||
```
|
||||
>这里只列举了一些常用的属性,更多属性请到LYEmptyView.h查看
|
||||
|
||||

|
||||
### <a id="二次封装"></a>5.二次封装
|
||||
第4小节的示例代码,修改emptyView的样式需要一个个属性单独去改,如果项目中每个界面都这么写就显得很麻烦,而且不易维护<br>
|
||||
解决办法是对库进行二次封装,二次封装后,对UI样式单独管理,方便维护<br>
|
||||
|
||||
##### 1)新建一个类继承自LYEmptyView,例如demo中的MyDIYEmpty
|
||||
##### 2)重写`- (void)prepare` 方法,并修改想要改变的元素的UI样式
|
||||
```Objective-C
|
||||
- (void)prepare{
|
||||
[super prepare];
|
||||
|
||||
self.titleLabFont = [UIFont systemFontOfSize:25];
|
||||
self.titleLabTextColor = MainColor(90, 180, 160);
|
||||
|
||||
self.detailLabFont = [UIFont systemFontOfSize:17];
|
||||
self.detailLabTextColor = MainColor(180, 120, 90);
|
||||
self.detailLabMaxLines = 5;
|
||||
|
||||
self.actionBtnBackGroundColor = MainColor(90, 180, 160);
|
||||
self.actionBtnTitleColor = [UIColor whiteColor];
|
||||
}
|
||||
```
|
||||
操作上面的两步就可实现对样式的单独管理<br>
|
||||
调用方法不变,只是调用的类变成了MYDiyEmpty
|
||||
```Objective-C
|
||||
self.tableView.ly_emptyView = [MyDIYEmpty emptyActionViewWithImageStr:@"noData"
|
||||
titleStr:@"无数据"
|
||||
detailStr:@"请稍后再试!"
|
||||
btnTitleStr:@"重新加载"
|
||||
btnClickBlock:^{}];
|
||||
```
|
||||
##### 3)进一步封装显示的元素内容,比如无数据状态图、无网络状态图<br>
|
||||
在MyDIYEmpty.h定义方法`+ (instancetype)diyNoDataEmpty;`<br>
|
||||
在MyDIYEmpty.m实现方法
|
||||
```Objective-C
|
||||
+ (instancetype)diyNoDataEmpty{
|
||||
return [MyDIYEmpty emptyViewWithImageStr:@"nodata"
|
||||
titleStr:@"暂无数据"
|
||||
detailStr:@"请检查您的网络连接是否正确!"];
|
||||
}
|
||||
```
|
||||
>经过3步封装,自定义了UI样式,使管理更方便,使调用更简洁<br>
|
||||
self.tableView.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];
|
||||
|
||||
### <a id="延迟显示emptyView"></a>6.延迟显示emptyView
|
||||
如示例1图,框架自动根据DataSource计算是否显示emptyView,在空页面发起网络请求时,DataSource肯定为空,会自动显示emptyView,有的产品需求可能不希望这样,希望发起请求时暂时隐藏emptyView。
|
||||
本框架提供了两个方法可实现此需求,两个方法都是scrollView的分类,调用非常方便
|
||||
```Objective-C
|
||||
/**
|
||||
一般用于开始请求网络时调用,ly_startLoading调用时会暂时隐藏emptyView
|
||||
当调用ly_endLoading方法时,ly_endLoading方法内部会根据当前的tableView/collectionView的
|
||||
DataSource来自动判断是否显示emptyView
|
||||
*/
|
||||
- (void)ly_startLoading;
|
||||
|
||||
/**
|
||||
在想要刷新emptyView状态时调用
|
||||
注意:ly_endLoading 的调用时机,有刷新UI的地方一定要等到刷新UI的方法之后调用,
|
||||
因为只有刷新了UI,view的DataSource才会更新,故调用此方法才能正确判断是否有内容。
|
||||
*/
|
||||
- (void)ly_endLoading;
|
||||
```
|
||||
|
||||
*注意点:使用这两个方法,请先将emptyView的autoShowEmptyView属性置为NO,关闭自动显隐
|
||||
|
||||
以下是调用示例(具体细节可参看demo中的demo2)
|
||||
```Objective-C
|
||||
//1.先设置样式
|
||||
self.tableView.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];
|
||||
//2.关闭自动显隐(此步可封装进自定义类中,相关调用就可省去这步)
|
||||
self.tableView.ly_emptyView.autoShowEmptyView = NO;
|
||||
//3.网络请求时调用
|
||||
[self.tableView ly_startLoading];
|
||||
//4.刷新UI时调用(保证在刷新UI后调用)
|
||||
[self.tableView ly_endLoading];
|
||||
```
|
||||
|
||||

|
||||
|
||||
### <a id="特殊需求,手动控制emptyView的显示隐藏"></a>7.特殊需求,手动控制emptyView的显示隐藏
|
||||
在某些特殊界面下,有的tableView/collectionView有固定的一些死数据,其它的数据根据网络加载,这时根据以上的示例方法可能达不到这需求。<br>
|
||||
本框架提供另外的两个方法来解决这个问题。
|
||||
|
||||
```Objective-C
|
||||
/**
|
||||
手动调用显示emptyView
|
||||
*/
|
||||
- (void)ly_showEmptyView;
|
||||
|
||||
/**
|
||||
手动调用隐藏emptyView
|
||||
*/
|
||||
- (void)ly_hideEmptyView;
|
||||
```
|
||||
|
||||
*注意点:使用这两个方法,请先将emptyView的autoShowEmptyView属性置为NO,关闭自动显隐
|
||||
|
||||
以下是调用示例(具体细节可参看demo中的demo4)
|
||||
```Objective-C
|
||||
//1.先设置样式
|
||||
self.tableView.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];
|
||||
//2.关闭自动显隐(此步可封装进自定义类中,相关调用就可省去这步)
|
||||
self.tableView.ly_emptyView.autoShowEmptyView = NO;
|
||||
//3.显示emptyView
|
||||
[self.tableView ly_showEmptyView];
|
||||
//4.隐藏emptyView
|
||||
[self.tableView ly_hideEmptyView];
|
||||
```
|
||||
|
||||

|
||||
|
||||
### <a id="普通view调用示例"></a>8.普通view调用示例
|
||||
因普通view(包括scrollView)没有DataSource,代码层面无法判断view上有无数据,所以view想要实现占位图,
|
||||
还需通过两个方法来手动控制emptyView的显示和隐藏。
|
||||
以下是调用示例
|
||||
```Objective-C
|
||||
//1.先设置样式
|
||||
self.view.ly_emptyView = [MyDIYEmpty diyNoDataEmpty];
|
||||
//2.显示emptyView
|
||||
[self.view ly_showEmptyView];
|
||||
//3.隐藏emptyView
|
||||
[self.view ly_hideEmptyView];
|
||||
```
|
||||
### <a id="占位图完全覆盖父视图"></a>9.占位图完全覆盖父视图
|
||||
每个项目需求不同,有的占位图内容多大,占位图就多大,这种情况是默认的,不用设置属性。而有的占位图想要和父视图一样大,以达到覆盖住父视图的目的,这种情况下将LYEmptyView的emptyViewIsCompleteCoverSuperView属性值设置为YES即可。
|
||||
```Objective-C
|
||||
DemoEmptyView *emptyView = [DemoEmptyView diyEmptyView];
|
||||
emptyView.emptyViewIsCompleteCoverSuperView = YES;//完全覆盖父视图,背景色默认为浅白色,可自行设置
|
||||
//emptyView.backgroundColor = [UIColor redColor];//自己设置背景色为红色,此设置也可封装到公共的地方(DemoEmptyView),就不用每次都单独设置了
|
||||
self.tableView.ly_emptyView = emptyView;
|
||||
```
|
||||
|
||||
## 更新记录
|
||||
|
||||
### 2019-08-16 (pod V1.3.0)
|
||||
* 1.detailLab添加行间距属性
|
||||
* 2.每个子控件可单独设置间距
|
||||
* 3.actionBtn添加渐变背景颜色属性
|
||||
* 4.更改添加emptyView时其显隐的逻辑
|
||||
|
||||
### 2019-07-04 (pod V1.2.5)
|
||||
* 1.新增属性:按钮宽度actionBtnWidth
|
||||
* 2.修改属性默认值:按钮的圆角actionBtnCornerRadius默认改为0
|
||||
|
||||
### 2019-06-18 (pod V1.2.4)
|
||||
* 1.将点击重试事件加到emptyView上(当设置empty完全覆盖父视图时,就可实现点击屏幕重试的效果)
|
||||
* 2.swift项目中imageNamed:方法string为nil时崩溃解决
|
||||
|
||||
### 2018-12-04 (pod V1.2.3)
|
||||
* 1.fix bug:当子控件的文字被设置为空并再次设置为非空时, 子控件无法正常显示
|
||||
* 2.新增属性:ignoreContentInset,是否忽略scrollView的contentInset
|
||||
|
||||
### 2018-09-11 (pod V1.2.2)
|
||||
* 新增构造方法,具体请查看LYEmptyBaseView.h
|
||||
|
||||
### 2018-08-22 (pod V1.2.1)
|
||||
* 大神的建议,不要手动调用layoutSubviews。优化baseView里setter方法调用的重绘机制,使用setNeedsLayout更加优美
|
||||
|
||||
### 2018-07-31 (pod V1.2.0)
|
||||
* 新增属性:emptyViewIsCompleteCoverSuperView, 占位图是否完全覆盖父视图
|
||||
|
||||
### 2018-05-11 (pod V1.1.0)
|
||||
* 新增普通View可设置占位图,实现所有的View都能集成占位图
|
||||
|
||||
### 2018-03-26 (pod V1.0.3)
|
||||
* 添加reloadSections、reloadRows、reloadItems 等方法的监听
|
||||
* emptyBaseView setter 方法bug fix
|
||||
|
||||
### 2018-02-09 (pod V1.0.2)
|
||||
* 解决只是在导入本框架的情况下,导致UIScrollView上的内容不显示的bug
|
||||
|
||||
|
||||
## 技术交流
|
||||
本人QQ:944801216<br>
|
||||
技术交流群:818290484<br>
|
||||
大家有任何的问题和建议,可以联系我,我一定尽力为大家解决问题,也可以进群和大家一起交流。
|
||||
Reference in New Issue
Block a user