|
19 | 19 |
|
20 | 20 | //按钮字体大小
|
21 | 21 | #define kActionBtnFont [UIFont systemFontOfSize:14.f]
|
| 22 | + |
22 | 23 | //按钮高度
|
23 | 24 | #define kActionBtnHeight 40.f
|
| 25 | +//按钮宽度 |
| 26 | +#define kActionBtnWidth 120.f |
24 | 27 | //水平方向内边距
|
25 | 28 | #define kActionBtnHorizontalMargin 30.f
|
26 | 29 |
|
@@ -48,12 +51,20 @@ @implementation LYEmptyView
|
48 | 51 | CGFloat contentHeight; //内容物高度
|
49 | 52 | CGFloat subViweMargin; //间距
|
50 | 53 | }
|
| 54 | + |
| 55 | +- (void)initialize{ |
| 56 | + self.actionBtnHeight = 40.f; |
| 57 | + self.actionBtnWidth = 120.f; |
| 58 | + self.actionBtnHorizontalMargin = 30.f; |
| 59 | +} |
| 60 | + |
51 | 61 | - (void)prepare{
|
52 | 62 | [super prepare];
|
53 | 63 |
|
54 | 64 | self.autoShowEmptyView = YES; //默认自动显隐
|
55 | 65 | self.contentViewY = 1000; //默认值,用来判断是否设置过content的Y值
|
56 | 66 | }
|
| 67 | + |
57 | 68 | - (void)setupSubviews{
|
58 | 69 | [super setupSubviews];
|
59 | 70 |
|
@@ -243,20 +254,28 @@ - (void)setupActionBtn:(NSString *)btnTitle target:(id)target action:(SEL)action
|
243 | 254 |
|
244 | 255 | UIFont *font = self.actionBtnFont.pointSize ? self.actionBtnFont : kActionBtnFont;
|
245 | 256 | 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; |
253 | 265 | CGSize textSize = [self returnTextWidth:btnTitle size:CGSizeMake(contentMaxWidth, fontSize) font:font];//计算得出title文字内容大小
|
254 | 266 | 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; |
256 | 276 | }
|
257 | 277 |
|
258 |
| - //按钮的宽高 |
259 |
| - CGFloat btnWidth = textSize.width + horiMargin * 2; |
| 278 | + //按钮的高 |
260 | 279 | CGFloat btnHeight = height;
|
261 | 280 | btnWidth = btnWidth > contentMaxWidth ? contentMaxWidth : btnWidth;
|
262 | 281 |
|
@@ -404,6 +423,15 @@ - (void)setActionBtnHeight:(CGFloat)actionBtnHeight{
|
404 | 423 | }
|
405 | 424 | }
|
406 | 425 | }
|
| 426 | +- (void)setActionBtnWidth:(CGFloat)actionBtnWidth{ |
| 427 | + if (_actionBtnWidth != actionBtnWidth) { |
| 428 | + _actionBtnWidth = actionBtnWidth; |
| 429 | + |
| 430 | + if (_actionButton) { |
| 431 | + [self setupSubviews]; |
| 432 | + } |
| 433 | + } |
| 434 | +} |
407 | 435 | - (void)setActionBtnHorizontalMargin:(CGFloat)actionBtnHorizontalMargin{
|
408 | 436 | if (_actionBtnHorizontalMargin != actionBtnHorizontalMargin) {
|
409 | 437 | _actionBtnHorizontalMargin = actionBtnHorizontalMargin;
|
|
0 commit comments