From 8d3d32f4a9c81322afcd4a292ca15fb1e38dc4bc Mon Sep 17 00:00:00 2001 From: 0x1306a94 <0x1306a94@gmail.com> Date: Tue, 19 Aug 2025 14:06:44 +0800 Subject: [PATCH] =?UTF-8?q?QMUIAlertController=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=A5=E6=A0=BC=E6=8C=89=E7=85=A7=E6=B7=BB=E5=8A=A0=E7=9A=84?= =?UTF-8?q?Action=E9=A1=BA=E5=BA=8F=E6=8E=92=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMUIKit/QMUIComponents/QMUIAlertController.h | 7 +++++++ QMUIKit/QMUIComponents/QMUIAlertController.m | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/QMUIKit/QMUIComponents/QMUIAlertController.h b/QMUIKit/QMUIComponents/QMUIAlertController.h index ca1a82be..3d45b549 100644 --- a/QMUIKit/QMUIComponents/QMUIAlertController.h +++ b/QMUIKit/QMUIComponents/QMUIAlertController.h @@ -278,6 +278,13 @@ typedef NS_ENUM(NSInteger, QMUIAlertControllerStyle) { */ @property(nonatomic, assign) BOOL orderActionsByAddedOrdered; +/** + * 设置按钮的排序是否要严格按照用户添加的顺序来决定,默认为NO。 + * + * 如果 strictOrderActionsByAddedOrdered 为 YES,则按钮的顺序将严格按照添加的顺序排列,不受其他因素影响。 + */ +@property (nonatomic, assign) BOOL strictOrderActionsByAddedOrdered; + /// dimmingView 是否响应点击,alert 默认为NO,sheet 默认为YES @property(nonatomic, assign) BOOL shouldRespondDimmingViewTouch; diff --git a/QMUIKit/QMUIComponents/QMUIAlertController.m b/QMUIKit/QMUIComponents/QMUIAlertController.m index 32a201a2..e8e1a45e 100644 --- a/QMUIKit/QMUIComponents/QMUIAlertController.m +++ b/QMUIKit/QMUIComponents/QMUIAlertController.m @@ -605,10 +605,10 @@ - (void)viewDidLayoutSubviews { } if (!verticalLayout) { // 对齐系统,先 add 的在右边,后 add 的在左边 - QMUIAlertAction *leftAction = newOrderActions[1]; + QMUIAlertAction *leftAction = self.strictOrderActionsByAddedOrdered ? newOrderActions[0] : newOrderActions[1]; leftAction.button.frame = CGRectMake(0, contentOriginY, CGRectGetWidth(self.buttonScrollView.bounds) / 2, self.alertButtonHeight); leftAction.button.qmui_borderPosition = QMUIViewBorderPositionRight; - QMUIAlertAction *rightAction = newOrderActions[0]; + QMUIAlertAction *rightAction = self.strictOrderActionsByAddedOrdered ? newOrderActions[1] : newOrderActions[0]; rightAction.button.frame = CGRectMake(CGRectGetMaxX(leftAction.button.frame), contentOriginY, CGRectGetWidth(self.buttonScrollView.bounds) / 2, self.alertButtonHeight); if (shouldShowSeparatorAtTopOfButtonAtFirstLine) { leftAction.button.qmui_borderPosition |= QMUIViewBorderPositionTop; @@ -796,6 +796,10 @@ - (void)viewDidLayoutSubviews { } - (NSArray *)orderedAlertActions:(NSArray *)actions { + if (self.strictOrderActionsByAddedOrdered) { + return actions; + } + NSMutableArray *newActions = [[NSMutableArray alloc] init]; // 按照用户addAction的先后顺序来排序 if (self.orderActionsByAddedOrdered) {