Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: ios/chrome/browser/ui/settings/cells/card_multiline_item.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/settings/cells/card_multiline_item.h"
6
7 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
8 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
14 namespace {
15 // Padding used on the leading and trailing edges of the cell.
16 const CGFloat kHorizontalPadding = 16;
17
18 // Padding used on the top and bottom edges of the cell.
19 const CGFloat kVerticalPadding = 16;
20 } // namespace
21
22 @implementation CardMultilineItem
23
24 @synthesize text = _text;
25
26 - (instancetype)initWithType:(NSInteger)type {
27 self = [super initWithType:type];
28 if (self) {
29 self.cellClass = [CardMultilineCell class];
30 }
31 return self;
32 }
33
34 #pragma mark CollectionViewItem
35
36 - (void)configureCell:(CardMultilineCell*)cell {
37 [super configureCell:cell];
38 cell.textLabel.text = self.text;
39 }
40
41 @end
42
43 @implementation CardMultilineCell
44
45 @synthesize textLabel = _textLabel;
46
47 - (instancetype)initWithFrame:(CGRect)frame {
48 self = [super initWithFrame:frame];
49 if (self) {
50 UIView* contentView = self.contentView;
51
52 _textLabel = [[UILabel alloc] init];
53 _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
54 [contentView addSubview:_textLabel];
55
56 _textLabel.font =
57 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14];
58 _textLabel.textColor = [[MDCPalette greyPalette] tint900];
59 _textLabel.numberOfLines = 0;
60
61 // Set up the constraints.
62 [NSLayoutConstraint activateConstraints:@[
63 [_textLabel.leadingAnchor
64 constraintEqualToAnchor:contentView.leadingAnchor
65 constant:kHorizontalPadding],
66 [_textLabel.trailingAnchor
67 constraintEqualToAnchor:contentView.trailingAnchor
68 constant:-kHorizontalPadding],
69 [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor
70 constant:kVerticalPadding],
71 [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor
72 constant:-kVerticalPadding],
73 ]];
74 }
75 return self;
76 }
77
78 // Implements -layoutSubviews as per instructions in documentation for
79 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
80 - (void)layoutSubviews {
81 [super layoutSubviews];
82
83 // Adjust the text label preferredMaxLayoutWidth when the parent's width
84 // changes, for instance on screen rotation.
85 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
86 self.textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding;
87
88 // Re-layout with the new preferred width to allow the label to adjust its
89 // height.
90 [super layoutSubviews];
91 }
92
93 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698