|
25 | 25 | #import "MDCTypography.h"
|
26 | 26 | #import "UIFont+MaterialTypography.h"
|
27 | 27 | #import "MDCMath.h"
|
28 |
| -#import <MDFInternationalization/MDFInternationalization.h> |
| 28 | +#import <MDFInternationalization/MDFRTL.h> |
29 | 29 |
|
30 | 30 | NS_ASSUME_NONNULL_BEGIN
|
31 | 31 |
|
@@ -542,7 +542,11 @@ - (CGSize)actionButtonsSizeInVerticalLayout {
|
542 | 542 | UIButton *button = buttons[index];
|
543 | 543 | CGSize buttonSize = [button sizeThatFits:size];
|
544 | 544 | CGFloat minButtonHeight = [self buttonHeight];
|
545 |
| - buttonSize.height = MAX(buttonSize.height, minButtonHeight); |
| 545 | + if (self.adjustButtonVerticalMargin) { |
| 546 | + buttonSize.height = MAX(button.titleLabel.frame.size.height, minButtonHeight); |
| 547 | + } else { |
| 548 | + buttonSize.height = MAX(buttonSize.height, minButtonHeight); |
| 549 | + } |
546 | 550 | size.height += buttonSize.height;
|
547 | 551 | size.width = MAX(size.width, buttonSize.width + widthInset);
|
548 | 552 | if (button != buttons.lastObject) {
|
@@ -994,11 +998,18 @@ - (void)layoutSubviews {
|
994 | 998 | for (UIButton *button in buttons) {
|
995 | 999 | [button sizeToFit];
|
996 | 1000 | CGRect buttonFrame = button.frame;
|
| 1001 | + CGFloat buttonTitleHeight = CGRectGetHeight(buttonFrame); |
| 1002 | + CGFloat buttonTitleWidth = CGRectGetWidth(buttonFrame); |
| 1003 | + if (self.adjustButtonVerticalMargin) { |
| 1004 | + buttonTitleHeight = MAX(M3CDialogActionMinHeight, button.titleLabel.frame.size.height); |
| 1005 | + button.titleLabel.preferredMaxLayoutWidth = button.titleLabel.frame.size.width; |
| 1006 | + buttonTitleWidth = button.intrinsicContentSize.width; |
| 1007 | + } |
997 | 1008 | CGFloat minTouchTargetHeight =
|
998 | 1009 | self.isM3CButtonEnabled ? M3CDialogActionMinHeight : MDCDialogActionMinTouchTarget;
|
999 | 1010 | button.frame = CGRectMake(buttonFrame.origin.x, buttonFrame.origin.y,
|
1000 |
| - MAX(MDCDialogActionMinTouchTarget, CGRectGetWidth(buttonFrame)), |
1001 |
| - MAX(minTouchTargetHeight, CGRectGetHeight(buttonFrame))); |
| 1011 | + MAX(MDCDialogActionMinTouchTarget, buttonTitleWidth), |
| 1012 | + MAX(minTouchTargetHeight, buttonTitleHeight)); |
1002 | 1013 | }
|
1003 | 1014 |
|
1004 | 1015 | if (self.isVerticalActionsLayout) {
|
@@ -1161,7 +1172,23 @@ - (void)layoutVerticalButtons:(NSArray<UIButton *> *)buttons {
|
1161 | 1172 | UIButton *nextButton = buttons[index + 1];
|
1162 | 1173 | CGFloat verticalMargin = [self actionsVerticalMarginBetweenTopButton:button
|
1163 | 1174 | bottomButton:nextButton];
|
1164 |
| - buttonCenter.y += multiplier * verticalMargin; |
| 1175 | + if (self.adjustButtonVerticalMargin) { |
| 1176 | + // Get the font's line height |
| 1177 | + CGFloat titleHeight = button.titleLabel.frame.size.height; |
| 1178 | + CGFloat lineHeight = button.titleLabel.font.lineHeight; |
| 1179 | + |
| 1180 | + // Check if the title height exceeds the line height (indicating multi-line text) |
| 1181 | + BOOL isMultiLine = titleHeight > lineHeight; |
| 1182 | + |
| 1183 | + if (isMultiLine) { |
| 1184 | + buttonCenter.y += multiplier * verticalMargin - 3; |
| 1185 | + } else { |
| 1186 | + buttonCenter.y += multiplier * verticalMargin; |
| 1187 | + } |
| 1188 | + |
| 1189 | + } else { |
| 1190 | + buttonCenter.y += multiplier * verticalMargin; |
| 1191 | + } |
1165 | 1192 | }
|
1166 | 1193 | }
|
1167 | 1194 |
|
|
0 commit comments