From 9f4110b24ac28168cd00604767597eb8c28f8d27 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Mon, 10 Nov 2025 15:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/Class/Common/V/KBAlert.h | 10 ++++++++- keyBoard/Class/Common/V/KBAlert.m | 21 ++++++++++++++++++- keyBoard/Class/Home/VC/HomeHotVC.m | 4 ++-- .../Class/Search/V/KBSearchSectionHeader.h | 8 +++++-- .../Class/Search/V/KBSearchSectionHeader.m | 18 ++++++++++++++-- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/keyBoard/Class/Common/V/KBAlert.h b/keyBoard/Class/Common/V/KBAlert.h index a92b341..e41dfef 100644 --- a/keyBoard/Class/Common/V/KBAlert.h +++ b/keyBoard/Class/Common/V/KBAlert.h @@ -48,6 +48,15 @@ typedef void (^KBAlertTextHandler)(NSString * _Nullable text, BOOL ok); cancel:(nullable NSString *)cancelTitle completion:(KBAlertBoolHandler)completion; +/// 自定义“确定/取消”按钮颜色(为 nil 时使用系统默认) ++ (void)confirmTitle:(nullable NSString *)title + message:(nullable NSString *)message + ok:(nullable NSString *)okTitle + cancel:(nullable NSString *)cancelTitle + okColor:(nullable UIColor *)okColor + cancelColor:(nullable UIColor *)cancelColor + completion:(KBAlertBoolHandler)completion; + #pragma mark - 输入框(单行) /// 带单个输入框;ok=YES 时返回输入内容。 + (void)promptTitle:(nullable NSString *)title @@ -72,4 +81,3 @@ typedef void (^KBAlertTextHandler)(NSString * _Nullable text, BOOL ok); @end NS_ASSUME_NONNULL_END - diff --git a/keyBoard/Class/Common/V/KBAlert.m b/keyBoard/Class/Common/V/KBAlert.m index 1e85a38..ee1a196 100644 --- a/keyBoard/Class/Common/V/KBAlert.m +++ b/keyBoard/Class/Common/V/KBAlert.m @@ -119,6 +119,22 @@ static __weak UIViewController *sDefaultPresenter = nil; // 可选外部指定 ok:(NSString *)okTitle cancel:(NSString *)cancelTitle completion:(KBAlertBoolHandler)completion { + [self confirmTitle:title message:message ok:okTitle cancel:cancelTitle okColor:nil cancelColor:nil completion:completion]; +} + +// KVC 方式设置 action 文字颜色(非公开 API,做保护) +static inline void KBSetActionTitleColor(UIAlertAction *action, UIColor *color) { + if (!color || !action) return; + @try { [action setValue:color forKey:@"titleTextColor"]; } @catch (__unused NSException *e) {} +} + ++ (void)confirmTitle:(NSString *)title + message:(NSString *)message + ok:(NSString *)okTitle + cancel:(NSString *)cancelTitle + okColor:(UIColor *)okColor + cancelColor:(UIColor *)cancelColor + completion:(KBAlertBoolHandler)completion { [self enqueuePresent:^{ UIViewController *vc = [self presentingVC]; if (!vc) { [self _markFinishedAndContinue]; return; } @@ -138,6 +154,10 @@ static __weak UIViewController *sDefaultPresenter = nil; // 可选外部指定 [wac dismissViewControllerAnimated:YES completion:nil]; [KBAlert _markFinishedAndContinue]; }]; + // 自定义颜色 + KBSetActionTitleColor(okAct, okColor); + KBSetActionTitleColor(cancelAct, cancelColor); + [ac addAction:cancelAct]; [ac addAction:okAct]; [vc presentViewController:ac animated:YES completion:nil]; @@ -221,4 +241,3 @@ static __weak UIViewController *sDefaultPresenter = nil; // 可选外部指定 } @end - diff --git a/keyBoard/Class/Home/VC/HomeHotVC.m b/keyBoard/Class/Home/VC/HomeHotVC.m index 1a8e47d..ae5f5ae 100644 --- a/keyBoard/Class/Home/VC/HomeHotVC.m +++ b/keyBoard/Class/Home/VC/HomeHotVC.m @@ -81,9 +81,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; -// KBSearchVC *vc = [[KBSearchVC alloc] init]; + KBSearchVC *vc = [[KBSearchVC alloc] init]; // [self.navigationController pushViewController:vc animated:true]; -// UINavigationController *nav = KB_CURRENT_NAV; + UINavigationController *nav = KB_CURRENT_NAV; // [nav pushViewController:vc animated:true]; NSLog(@"==="); diff --git a/keyBoard/Class/Search/V/KBSearchSectionHeader.h b/keyBoard/Class/Search/V/KBSearchSectionHeader.h index 4faea23..7048c54 100644 --- a/keyBoard/Class/Search/V/KBSearchSectionHeader.h +++ b/keyBoard/Class/Search/V/KBSearchSectionHeader.h @@ -20,10 +20,14 @@ NS_ASSUME_NONNULL_BEGIN /// 配置标题与是否显示垃圾桶 - (void)configWithTitle:(NSString *)title showTrash:(BOOL)showTrash; -/// 清除按钮点击回调 +/// 清除按钮点击回调(用户在弹窗中点击“确定”后触发) @property (nonatomic, copy) void(^onTapTrash)(void); +/// “确定”按钮颜色(默认黑色) +@property (nonatomic, strong, nullable) UIColor *confirmColor; +/// “取消”按钮颜色(默认黑色) +@property (nonatomic, strong, nullable) UIColor *cancelColor; + @end NS_ASSUME_NONNULL_END - diff --git a/keyBoard/Class/Search/V/KBSearchSectionHeader.m b/keyBoard/Class/Search/V/KBSearchSectionHeader.m index 792f27f..220e97f 100644 --- a/keyBoard/Class/Search/V/KBSearchSectionHeader.m +++ b/keyBoard/Class/Search/V/KBSearchSectionHeader.m @@ -4,6 +4,7 @@ // #import "KBSearchSectionHeader.h" +#import "KBAlert.h" @interface KBSearchSectionHeader () @property (nonatomic, strong, readwrite) UILabel *titleLabel; @@ -15,6 +16,8 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setupUI]; + _confirmColor = [UIColor redColor]; + _cancelColor = [UIColor blackColor]; } return self; } @@ -39,7 +42,19 @@ } - (void)tapTrash { - if (self.onTapTrash) { self.onTapTrash(); } + // 弹出确认框:是否删除所有历史记录 + __weak typeof(self) weakSelf = self; + [KBAlert confirmTitle:@"清空历史" + message:@"是否删除所有历史记录?" + ok:@"确定" + cancel:@"取消" + okColor:weakSelf.confirmColor + cancelColor:weakSelf.cancelColor + completion:^(BOOL ok) { + if (ok && weakSelf.onTapTrash) { + weakSelf.onTapTrash(); + } + }]; } - (void)configWithTitle:(NSString *)title showTrash:(BOOL)showTrash { @@ -69,4 +84,3 @@ } @end -