添加弹窗

This commit is contained in:
2025-11-10 15:55:36 +08:00
parent 1cdc17b710
commit 9f4110b24a
5 changed files with 53 additions and 8 deletions

View File

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

View File

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