恢复默认皮肤
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
@interface KBSkinCenterVC () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property (nonatomic, strong) UITableView *tableView;
|
||||
@property (nonatomic, copy) NSArray<NSDictionary *> *skins; // 每个元素即一套皮肤的 JSON(与后端约定格式一致)
|
||||
@property (nonatomic, strong) UIButton *resetButton;
|
||||
@end
|
||||
|
||||
@implementation KBSkinCenterVC
|
||||
@@ -146,7 +147,7 @@
|
||||
self.skins = @[
|
||||
@{
|
||||
@"id": @"local001",
|
||||
@"name": @"本地001皮肤",
|
||||
@"name": KBLocalized(@"本地001皮肤"),
|
||||
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
||||
@"zip_url": @"bundle://001.zip",
|
||||
|
||||
@@ -164,6 +165,30 @@
|
||||
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.tableView.delegate = self; self.tableView.dataSource = self;
|
||||
[self.view addSubview:self.tableView];
|
||||
|
||||
// 底部添加“恢复默认皮肤”测试按钮
|
||||
UIButton *reset = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[reset setTitle:KBLocalized(@"恢复默认皮肤") forState:UIControlStateNormal];
|
||||
reset.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
||||
reset.layer.cornerRadius = 8.0;
|
||||
reset.layer.borderWidth = 1.0;
|
||||
reset.layer.borderColor = [UIColor colorWithWhite:0.85 alpha:1.0].CGColor;
|
||||
[reset addTarget:self action:@selector(onResetDefault:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:reset];
|
||||
self.resetButton = reset;
|
||||
|
||||
[reset mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.view).offset(16);
|
||||
make.right.equalTo(self.view).offset(-16);
|
||||
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-16);
|
||||
make.height.mas_equalTo(44);
|
||||
}];
|
||||
|
||||
// 让 tableView 的内容区域避免被按钮遮挡
|
||||
UIEdgeInsets inset = self.tableView.contentInset;
|
||||
inset.bottom += 44 + 24; // 按钮高度 + 上下间距
|
||||
self.tableView.contentInset = inset;
|
||||
self.tableView.scrollIndicatorInsets = inset;
|
||||
}
|
||||
|
||||
#pragma mark - UITableView
|
||||
@@ -188,11 +213,18 @@
|
||||
if (idx < 0 || idx >= self.skins.count) return;
|
||||
NSDictionary *skin = self.skins[idx];
|
||||
if (!skin) return;
|
||||
// 默认按远程 Zip 模式测试;如需本地 bundle,请改为 KBSkinSourceModeLocalBundleZip。
|
||||
[[KBSkinService shared] applySkinWithJSON:skin
|
||||
fromViewController:self
|
||||
mode:KBSkinSourceModeLocalBundleZip
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
- (void)onResetDefault:(UIButton *)sender {
|
||||
// 不需要皮肤 JSON,传空字典即可
|
||||
[[KBSkinService shared] applySkinWithJSON:@{}
|
||||
fromViewController:self
|
||||
mode:KBSkinSourceModeResetToDefault
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user