Index: ios/chrome/browser/ui/settings/cells/card_multiline_item.mm |
diff --git a/ios/chrome/browser/ui/settings/cells/card_multiline_item.mm b/ios/chrome/browser/ui/settings/cells/card_multiline_item.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2fcdb5bab6abae317e02787ce4719da47ac89e97 |
--- /dev/null |
+++ b/ios/chrome/browser/ui/settings/cells/card_multiline_item.mm |
@@ -0,0 +1,93 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/chrome/browser/ui/settings/cells/card_multiline_item.h" |
+ |
+#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" |
+#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h" |
+ |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
+namespace { |
+// Padding used on the leading and trailing edges of the cell. |
+const CGFloat kHorizontalPadding = 16; |
+ |
+// Padding used on the top and bottom edges of the cell. |
+const CGFloat kVerticalPadding = 16; |
+} // namespace |
+ |
+@implementation CardMultilineItem |
+ |
+@synthesize text = _text; |
+ |
+- (instancetype)initWithType:(NSInteger)type { |
+ self = [super initWithType:type]; |
+ if (self) { |
+ self.cellClass = [CardMultilineCell class]; |
+ } |
+ return self; |
+} |
+ |
+#pragma mark CollectionViewItem |
+ |
+- (void)configureCell:(CardMultilineCell*)cell { |
+ [super configureCell:cell]; |
+ cell.textLabel.text = self.text; |
+} |
+ |
+@end |
+ |
+@implementation CardMultilineCell |
+ |
+@synthesize textLabel = _textLabel; |
+ |
+- (instancetype)initWithFrame:(CGRect)frame { |
+ self = [super initWithFrame:frame]; |
+ if (self) { |
+ UIView* contentView = self.contentView; |
+ |
+ _textLabel = [[UILabel alloc] init]; |
+ _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
+ [contentView addSubview:_textLabel]; |
+ |
+ _textLabel.font = |
+ [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; |
+ _textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
+ _textLabel.numberOfLines = 0; |
+ |
+ // Set up the constraints. |
+ [NSLayoutConstraint activateConstraints:@[ |
+ [_textLabel.leadingAnchor |
+ constraintEqualToAnchor:contentView.leadingAnchor |
+ constant:kHorizontalPadding], |
+ [_textLabel.trailingAnchor |
+ constraintEqualToAnchor:contentView.trailingAnchor |
+ constant:-kHorizontalPadding], |
+ [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor |
+ constant:kVerticalPadding], |
+ [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor |
+ constant:-kVerticalPadding], |
+ ]]; |
+ } |
+ return self; |
+} |
+ |
+// Implements -layoutSubviews as per instructions in documentation for |
+// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. |
+- (void)layoutSubviews { |
+ [super layoutSubviews]; |
+ |
+ // Adjust the text label preferredMaxLayoutWidth when the parent's width |
+ // changes, for instance on screen rotation. |
+ CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
+ self.textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding; |
+ |
+ // Re-layout with the new preferred width to allow the label to adjust its |
+ // height. |
+ [super layoutSubviews]; |
+} |
+ |
+@end |