恢复默认皮肤

This commit is contained in:
2025-11-19 20:30:30 +08:00
parent 8dbaa9dcf6
commit f51fe1fac9
3 changed files with 45 additions and 3 deletions

View File

@@ -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

View File

@@ -20,6 +20,8 @@ typedef NS_ENUM(NSUInteger, KBSkinSourceMode) {
KBSkinSourceModeRemoteZip = 0,
/// 本地 bundle Zip从主 App bundle 中读取 zip_url 指定的 zip 文件并解压到 App Group
KBSkinSourceModeLocalBundleZip = 1,
/// 恢复到默认皮肤(忽略 skinJSON 中的资源字段)
KBSkinSourceModeResetToDefault = 2,
};
/// 皮肤下载与应用服务(仅主 App 使用)
@@ -31,7 +33,7 @@ typedef NS_ENUM(NSUInteger, KBSkinSourceMode) {
///
/// @param skinJSON 与后端约定的皮肤结构(包含 id/name/background_image/hidden_keys/key_icons 等)
/// @param presenting 用于弹出“键盘权限引导页”的控制器,可为 nil
/// @param mode 资源来源模式:远程 / 本地 bundle
/// @param mode 模式:远程 Zip、本地 bundle Zip或恢复默认皮肤
/// @param completion 应用完成回调(下载/写入全部结束后调用success 表示是否成功)
- (void)applySkinWithJSON:(NSDictionary *)skinJSON
fromViewController:(nullable UIViewController *)presenting

View File

@@ -51,6 +51,14 @@
fromViewController:(UIViewController *)presenting
mode:(KBSkinSourceMode)mode
completion:(KBSkinApplyCompletion)completion {
// KBSkinManager reset JSON
if (mode == KBSkinSourceModeResetToDefault) {
[[KBSkinManager shared] resetToDefault];
if (completion) completion(YES);
[KBHUD showInfo:KBLocalized(@"已恢复默认键盘皮肤")];
return;
}
if (skinJSON.count == 0) {
if (completion) completion(NO);
return;