From 9f7b3648fbc6f9a5bb726888e4b9b5b2dd9b8aa2 Mon Sep 17 00:00:00 2001 From: 0x1306a94 <0x1306a94@gmail.com> Date: Tue, 4 Nov 2025 09:34:17 +0800 Subject: [PATCH] =?UTF-8?q?QMUIAlertController=20Alert=E6=A0=B7=E5=BC=8FAc?= =?UTF-8?q?tions=20=E5=B8=83=E5=B1=80=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMUIKit/QMUIComponents/QMUIAlertController.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/QMUIKit/QMUIComponents/QMUIAlertController.m b/QMUIKit/QMUIComponents/QMUIAlertController.m index 32a201a2..00136a48 100644 --- a/QMUIKit/QMUIComponents/QMUIAlertController.m +++ b/QMUIKit/QMUIComponents/QMUIAlertController.m @@ -604,11 +604,15 @@ - (void)viewDidLayoutSubviews { } } if (!verticalLayout) { - // 对齐系统,先 add 的在右边,后 add 的在左边 - QMUIAlertAction *leftAction = newOrderActions[1]; + /** + * 对齐系统,先 add 的在右边,后 add 的在左边, 前提是存在 Cancel + * newOrderActions 已经是将Cancel 重排在最后了 + */ + BOOL needSwap = (newOrderActions.firstObject.style == QMUIAlertActionStyleCancel) || (newOrderActions.lastObject.style == QMUIAlertActionStyleCancel); + QMUIAlertAction *leftAction = needSwap ? newOrderActions[1] : newOrderActions[0]; leftAction.button.frame = CGRectMake(0, contentOriginY, CGRectGetWidth(self.buttonScrollView.bounds) / 2, self.alertButtonHeight); leftAction.button.qmui_borderPosition = QMUIViewBorderPositionRight; - QMUIAlertAction *rightAction = newOrderActions[0]; + QMUIAlertAction *rightAction = needSwap ? newOrderActions[0] : newOrderActions[1]; rightAction.button.frame = CGRectMake(CGRectGetMaxX(leftAction.button.frame), contentOriginY, CGRectGetWidth(self.buttonScrollView.bounds) / 2, self.alertButtonHeight); if (shouldShowSeparatorAtTopOfButtonAtFirstLine) { leftAction.button.qmui_borderPosition |= QMUIViewBorderPositionTop;