Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c61f4be

Browse files
author
liyang
committed
1.2.5版本更新
1.新增属性:按钮宽度actionBtnWidth 2.修改属性默认值:按钮的圆角actionBtnCornerRadius默认改为0
1 parent f7f01b1 commit c61f4be

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

LYEmptyView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
22

33
s.name = 'LYEmptyView'
44

5-
s.version = '1.2.3'
5+
s.version = '1.2.5'
66

77
s.summary = 'so esay integrate empty content view'
88

LYEmptyView/LYEmptyBaseView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ - (instancetype)init
1919
{
2020
self = [super init];
2121
if (self) {
22+
[self initialize];
2223
[self prepare];
2324
}
2425
return self;
2526
}
27+
28+
- (void)initialize{
29+
}
30+
2631
- (void)prepare{
2732
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
2833
}

LYEmptyView/LYEmptyView.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@
8585
*/
8686
@property (nonatomic, assign) CGFloat actionBtnHeight;
8787
/**
88-
水平方向内边距, default is 30.f
88+
按钮的宽度, default is 0.f, (此属性和actionBtnHorizontalMargin只有一个有效,都>0时,此属性优先级大)
89+
*/
90+
@property (nonatomic, assign) CGFloat actionBtnWidth;
91+
/**
92+
按钮的水平方向内边距, default is 30.f, (此属性和actionBtnWidth只有一个有效,都>0时,此属性优先级小)
8993
*/
9094
@property (nonatomic, assign) CGFloat actionBtnHorizontalMargin;
9195
/**
92-
按钮的圆角大小, default is 5.f
96+
按钮的圆角大小, default is 0
9397
*/
9498
@property (nonatomic, assign) CGFloat actionBtnCornerRadius;
9599
/**

LYEmptyView/LYEmptyView.m

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919

2020
//按钮字体大小
2121
#define kActionBtnFont [UIFont systemFontOfSize:14.f]
22+
2223
//按钮高度
2324
#define kActionBtnHeight 40.f
25+
//按钮宽度
26+
#define kActionBtnWidth 120.f
2427
//水平方向内边距
2528
#define kActionBtnHorizontalMargin 30.f
2629

@@ -48,12 +51,20 @@ @implementation LYEmptyView
4851
CGFloat contentHeight; //内容物高度
4952
CGFloat subViweMargin; //间距
5053
}
54+
55+
- (void)initialize{
56+
self.actionBtnHeight = 40.f;
57+
self.actionBtnWidth = 120.f;
58+
self.actionBtnHorizontalMargin = 30.f;
59+
}
60+
5161
- (void)prepare{
5262
[super prepare];
5363

5464
self.autoShowEmptyView = YES; //默认自动显隐
5565
self.contentViewY = 1000; //默认值,用来判断是否设置过content的Y值
5666
}
67+
5768
- (void)setupSubviews{
5869
[super setupSubviews];
5970

@@ -243,20 +254,28 @@ - (void)setupActionBtn:(NSString *)btnTitle target:(id)target action:(SEL)action
243254

244255
UIFont *font = self.actionBtnFont.pointSize ? self.actionBtnFont : kActionBtnFont;
245256
CGFloat fontSize = font.pointSize;
246-
UIColor *titleColor = self.actionBtnTitleColor ? self.actionBtnTitleColor : kBlackColor;
247-
UIColor *backGColor = self.actionBtnBackGroundColor ? self.actionBtnBackGroundColor : [UIColor whiteColor];
248-
UIColor *borderColor = self.actionBtnBorderColor ? self.actionBtnBorderColor : [UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1];
249-
CGFloat borderWidth = self.actionBtnBorderWidth ? self.actionBtnBorderWidth : 0.0f;
250-
CGFloat cornerRadius = self.actionBtnCornerRadius ? self.actionBtnCornerRadius : 5.f;
251-
CGFloat horiMargin = self.actionBtnHorizontalMargin ? self.actionBtnHorizontalMargin : kActionBtnHorizontalMargin;
252-
CGFloat height = self.actionBtnHeight ? self.actionBtnHeight : kActionBtnHeight;
257+
UIColor *titleColor = self.actionBtnTitleColor ?: kBlackColor;
258+
UIColor *backGColor = self.actionBtnBackGroundColor ?: [UIColor whiteColor];
259+
UIColor *borderColor = self.actionBtnBorderColor ?: [UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1.f];
260+
CGFloat borderWidth = self.actionBtnBorderWidth ?: 0;
261+
CGFloat cornerRadius = self.actionBtnCornerRadius ?: 0;
262+
CGFloat width = self.actionBtnWidth;
263+
CGFloat horiMargin = self.actionBtnHorizontalMargin;
264+
CGFloat height = self.actionBtnHeight;
253265
CGSize textSize = [self returnTextWidth:btnTitle size:CGSizeMake(contentMaxWidth, fontSize) font:font];//计算得出title文字内容大小
254266
if (height < textSize.height) {
255-
height = textSize.height + 4;
267+
height = textSize.height + 4.f;
268+
}
269+
270+
//按钮的宽
271+
CGFloat btnWidth = textSize.width;
272+
if (width) {
273+
btnWidth = width;
274+
} else if (horiMargin) {
275+
btnWidth = textSize.width + horiMargin * 2.f;
256276
}
257277

258-
//按钮的宽高
259-
CGFloat btnWidth = textSize.width + horiMargin * 2;
278+
//按钮的高
260279
CGFloat btnHeight = height;
261280
btnWidth = btnWidth > contentMaxWidth ? contentMaxWidth : btnWidth;
262281

@@ -404,6 +423,15 @@ - (void)setActionBtnHeight:(CGFloat)actionBtnHeight{
404423
}
405424
}
406425
}
426+
- (void)setActionBtnWidth:(CGFloat)actionBtnWidth{
427+
if (_actionBtnWidth != actionBtnWidth) {
428+
_actionBtnWidth = actionBtnWidth;
429+
430+
if (_actionButton) {
431+
[self setupSubviews];
432+
}
433+
}
434+
}
407435
- (void)setActionBtnHorizontalMargin:(CGFloat)actionBtnHorizontalMargin{
408436
if (_actionBtnHorizontalMargin != actionBtnHorizontalMargin) {
409437
_actionBtnHorizontalMargin = actionBtnHorizontalMargin;

0 commit comments

Comments
 (0)