Commit 4194f400 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix multiline labels when selected

This CL fixes the way the multilines labels are handling the accessory
view. Instead of getting resized when the accessory is added to the
view, they have a width taking into account the accessory view.

Bug: 911088
Change-Id: I153a0939600ca89d7f27c80ab411c287c6408398
Reviewed-on: https://chromium-review.googlesource.com/c/1363192
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614667}
parent 0d65e60a
...@@ -26,9 +26,8 @@ ...@@ -26,9 +26,8 @@
// ImportDataMultilineDetailCell implements an UITableViewCell // ImportDataMultilineDetailCell implements an UITableViewCell
// subclass containing two text labels: a "main" label and a "detail" label. // subclass containing two text labels: a "main" label and a "detail" label.
// The two labels are laid out on top of each other. The detail text can span // The two labels are laid out on top of each other and can span on multiple
// multiple lines. // lines. This is to be used with a ImportDataMultilineDetailItem.
// This is to be used with a ImportDataMultilineDetailItem.
@interface ImportDataMultilineDetailCell : UITableViewCell @interface ImportDataMultilineDetailCell : UITableViewCell
// UILabels corresponding to |text| and |detailText| from the item. // UILabels corresponding to |text| and |detailText| from the item.
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
const CGFloat kAccessoryWidth = 40;
} // namespace
@implementation ImportDataMultilineDetailItem @implementation ImportDataMultilineDetailItem
@synthesize accessoryType = _accessoryType; @synthesize accessoryType = _accessoryType;
...@@ -53,6 +57,7 @@ ...@@ -53,6 +57,7 @@
_textLabel = [[UILabel alloc] init]; _textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO; _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
_textLabel.numberOfLines = 0;
_textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; _textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_textLabel.adjustsFontForContentSizeCategory = YES; _textLabel.adjustsFontForContentSizeCategory = YES;
_textLabel.textColor = UIColor.blackColor; _textLabel.textColor = UIColor.blackColor;
...@@ -69,25 +74,42 @@ ...@@ -69,25 +74,42 @@
// Set up the constraints. // Set up the constraints.
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[_textLabel.topAnchor
constraintEqualToAnchor:contentView.topAnchor
constant:kTableViewLargeVerticalSpacing],
[_textLabel.leadingAnchor [_textLabel.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor
constant:kTableViewHorizontalSpacing], constant:kTableViewHorizontalSpacing],
[_textLabel.trailingAnchor [_textLabel.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor constraintLessThanOrEqualToAnchor:contentView.trailingAnchor
constant:-kTableViewHorizontalSpacing], constant:-kTableViewHorizontalSpacing],
[_textLabel.bottomAnchor
constraintEqualToAnchor:_detailTextLabel.topAnchor],
[_detailTextLabel.leadingAnchor [_detailTextLabel.leadingAnchor
constraintEqualToAnchor:_textLabel.leadingAnchor], constraintEqualToAnchor:_textLabel.leadingAnchor],
[_detailTextLabel.trailingAnchor [_detailTextLabel.trailingAnchor
constraintEqualToAnchor:_textLabel.trailingAnchor], constraintLessThanOrEqualToAnchor:contentView.trailingAnchor
[_textLabel.bottomAnchor constant:-kTableViewHorizontalSpacing],
constraintEqualToAnchor:_detailTextLabel.topAnchor], [_detailTextLabel.bottomAnchor
constraintEqualToAnchor:contentView.bottomAnchor
constant:-kTableViewLargeVerticalSpacing],
]]; ]];
AddOptionalVerticalPadding(contentView, _textLabel, _detailTextLabel,
kTableViewLargeVerticalSpacing);
} }
return self; return self;
} }
- (void)layoutSubviews {
// Make sure that the multiline labels' width isn't changed when the accessory
// is set.
self.detailTextLabel.preferredMaxLayoutWidth =
self.bounds.size.width -
(kAccessoryWidth + 2 * kTableViewHorizontalSpacing);
self.textLabel.preferredMaxLayoutWidth =
self.bounds.size.width -
(kAccessoryWidth + 2 * kTableViewHorizontalSpacing);
[super layoutSubviews];
}
#pragma mark Accessibility #pragma mark Accessibility
- (NSString*)accessibilityLabel { - (NSString*)accessibilityLabel {
......
...@@ -49,7 +49,7 @@ TEST_F(ImportDataMultilineDetailItemTest, ConfigureCell) { ...@@ -49,7 +49,7 @@ TEST_F(ImportDataMultilineDetailItemTest, ConfigureCell) {
TEST_F(ImportDataMultilineDetailItemTest, MultipleLines) { TEST_F(ImportDataMultilineDetailItemTest, MultipleLines) {
ImportDataMultilineDetailCell* cell = ImportDataMultilineDetailCell* cell =
[[ImportDataMultilineDetailCell alloc] init]; [[ImportDataMultilineDetailCell alloc] init];
EXPECT_EQ(1, cell.textLabel.numberOfLines); EXPECT_EQ(0, cell.textLabel.numberOfLines);
EXPECT_EQ(0, cell.detailTextLabel.numberOfLines); EXPECT_EQ(0, cell.detailTextLabel.numberOfLines);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment