添加LYEmptyView '~> 0.3.10'

This commit is contained in:
2025-11-09 20:54:14 +08:00
parent 883b222254
commit e5ddcc4308
34 changed files with 5454 additions and 3115 deletions

View 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

View 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
View 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
View 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; //,contentY
}
- (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;
//selfframecontent
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;
}
//scrollViewcontentInset
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

View 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 */

View 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的方法之后调用
因为只有刷新了UIview的DataSource才会更新故调用此方法才能正确判断是否有内容。
*/
- (void)ly_endLoading;
//调用下面两个手动显隐的方法不受DataSource的影响单独设置显示与隐藏前提是关闭autoShowEmptyView
/**
手动调用显示emptyView
*/
- (void)ly_showEmptyView;
/**
手动调用隐藏emptyView
*/
- (void)ly_hideEmptyView;
@end

View 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 (UITableViewUICollectionView)
- (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

View 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

View 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