Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions QMUIKit/QMUIComponents/QMUIAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions QMUIKit/QMUIComponents/QMUIAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -796,6 +796,10 @@ - (void)viewDidLayoutSubviews {
}

- (NSArray<QMUIAlertAction *> *)orderedAlertActions:(NSArray<QMUIAlertAction *> *)actions {
if (self.strictOrderActionsByAddedOrdered) {
return actions;
}

NSMutableArray<QMUIAlertAction *> *newActions = [[NSMutableArray alloc] init];
// 按照用户addAction的先后顺序来排序
if (self.orderActionsByAddedOrdered) {
Expand Down