1
This commit is contained in:
@@ -13,6 +13,15 @@
|
||||
#define KB_HAS_DZN 0
|
||||
#endif
|
||||
|
||||
// 可选引入:LYEmptyView(通过 Pod 集成),用于空态视图的“自动显隐+属性配置”方案
|
||||
#if __has_include(<LYEmptyView/UIView+Empty.h>)
|
||||
#import <LYEmptyView/UIView+Empty.h>
|
||||
#import <LYEmptyView/LYEmptyView.h>
|
||||
#define KB_HAS_LY 1
|
||||
#else
|
||||
#define KB_HAS_LY 0
|
||||
#endif
|
||||
|
||||
@interface BaseTableView ()
|
||||
#if KB_HAS_DZN
|
||||
<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
|
||||
@@ -127,4 +136,66 @@
|
||||
|
||||
#endif
|
||||
|
||||
// MARK: - LYEmptyView 快速挂载(与 DZN 二选一)
|
||||
- (void)kb_makeDefaultEmptyViewWithImage:(UIImage *)image
|
||||
title:(NSString *)title
|
||||
detail:(NSString *)detail
|
||||
buttonTitle:(NSString *)buttonTitle
|
||||
tapHandler:(KBEmptyAction)tapHandler
|
||||
buttonHandler:(KBEmptyAction)buttonHandler {
|
||||
#if KB_HAS_LY
|
||||
// 关闭 DZN,避免两套空态叠加
|
||||
self.useEmptyDataSet = NO;
|
||||
|
||||
// 默认文案
|
||||
NSString *t = title ?: @"暂无数据";
|
||||
|
||||
LYEmptyView *ev = nil;
|
||||
if (buttonTitle.length > 0) {
|
||||
// 带按钮(优先 block 方式)
|
||||
__weak typeof(self) weakSelf = self;
|
||||
ev = [LYEmptyView emptyActionViewWithImage:image
|
||||
titleStr:t
|
||||
detailStr:detail ?: @""
|
||||
btnTitleStr:buttonTitle
|
||||
btnClickBlock:^{ if (buttonHandler) buttonHandler(); [weakSelf setNeedsLayout]; }];
|
||||
} else {
|
||||
// 无按钮
|
||||
ev = [LYEmptyView emptyViewWithImage:image titleStr:t detailStr:detail ?: @""];
|
||||
}
|
||||
|
||||
// 点击空白区域
|
||||
if (tapHandler) {
|
||||
ev.tapEmptyViewBlock = ^{ tapHandler(); };
|
||||
}
|
||||
|
||||
// 统一样式(可按需微调)
|
||||
ev.emptyViewIsCompleteCoverSuperView = NO; // 不全屏覆盖,按内容大小布局
|
||||
ev.ignoreContentInset = YES; // 忽略 inset,避免导航/安全区影响
|
||||
ev.contentViewOffset = -10; // 轻微上移
|
||||
ev.subViewMargin = 14; // 子控件间距
|
||||
ev.titleLabFont = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
ev.titleLabTextColor = [UIColor colorWithWhite:0.45 alpha:1.0];
|
||||
ev.detailLabFont = [UIFont systemFontOfSize:14];
|
||||
ev.detailLabTextColor = [UIColor colorWithWhite:0.6 alpha:1.0];
|
||||
ev.detailLabLineSpacing = 3;
|
||||
ev.detailLabMaxLines = 2;
|
||||
ev.actionBtnFont = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];
|
||||
ev.actionBtnCornerRadius = 6;
|
||||
ev.actionBtnBorderWidth = 1;
|
||||
ev.actionBtnBorderColor = [UIColor colorWithWhite:0.88 alpha:1.0];
|
||||
ev.actionBtnTitleColor = [UIColor colorWithRed:0.22 green:0.49 blue:0.96 alpha:1.0];
|
||||
ev.actionBtnBackGroundColor = [UIColor whiteColor];
|
||||
ev.actionBtnHorizontalMargin = 20; // 自动宽度:文字 + padding*2
|
||||
|
||||
// 自动显隐交由控制层(网络请求)
|
||||
ev.autoShowEmptyView = NO;
|
||||
|
||||
self.ly_emptyView = (LYEmptyView *)ev;
|
||||
#else
|
||||
// 未集成 LYEmptyView 时不做任何处理,保持兼容
|
||||
(void)image; (void)title; (void)detail; (void)buttonTitle; (void)tapHandler; (void)buttonHandler;
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user