OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" | 5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" |
6 | 6 |
| 7 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 8 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 9 |
7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
8 #error "This file requires ARC support." | 11 #error "This file requires ARC support." |
9 #endif | 12 #endif |
10 | 13 |
11 namespace { | 14 namespace { |
12 const CGFloat kMargin = 16; | 15 const CGFloat kMargin = 16; |
13 const CGFloat kMinimalHeight = 48; | 16 const CGFloat kMinimalHeight = 48; |
14 } | 17 } |
15 | 18 |
16 @implementation CollectionViewTextCell | 19 @implementation CollectionViewTextCell |
17 | 20 |
18 @synthesize textLabel = _textLabel; | 21 @synthesize textLabel = _textLabel; |
19 @synthesize detailTextLabel = _detailTextLabel; | 22 @synthesize detailTextLabel = _detailTextLabel; |
20 | 23 |
21 - (instancetype)initWithFrame:(CGRect)frame { | 24 - (instancetype)initWithFrame:(CGRect)frame { |
22 self = [super initWithFrame:frame]; | 25 self = [super initWithFrame:frame]; |
23 if (self) { | 26 if (self) { |
24 UIView* containerView = [[UIView alloc] initWithFrame:CGRectZero]; | 27 UIView* containerView = [[UIView alloc] initWithFrame:CGRectZero]; |
25 containerView.translatesAutoresizingMaskIntoConstraints = NO; | 28 containerView.translatesAutoresizingMaskIntoConstraints = NO; |
26 [self.contentView addSubview:containerView]; | 29 [self.contentView addSubview:containerView]; |
27 | 30 |
28 _textLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 31 _textLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
29 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; | 32 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
30 [containerView addSubview:_textLabel]; | 33 [containerView addSubview:_textLabel]; |
31 | 34 |
32 _detailTextLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 35 _detailTextLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
33 _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO; | 36 _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO; |
34 [containerView addSubview:_detailTextLabel]; | 37 [containerView addSubview:_detailTextLabel]; |
35 | 38 |
| 39 // Set default font and text colors for labels. |
| 40 _textLabel.font = [MDCTypography body2Font]; |
| 41 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 42 _detailTextLabel.font = [MDCTypography body1Font]; |
| 43 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 44 |
36 [NSLayoutConstraint activateConstraints:@[ | 45 [NSLayoutConstraint activateConstraints:@[ |
37 // Total height. | 46 // Total height. |
38 // The MDC specs ask for at least 48 pt. | 47 // The MDC specs ask for at least 48 pt. |
39 [self.contentView.heightAnchor | 48 [self.contentView.heightAnchor |
40 constraintGreaterThanOrEqualToConstant:kMinimalHeight], | 49 constraintGreaterThanOrEqualToConstant:kMinimalHeight], |
41 | 50 |
42 // Container. | 51 // Container. |
43 [containerView.leadingAnchor | 52 [containerView.leadingAnchor |
44 constraintEqualToAnchor:self.contentView.leadingAnchor | 53 constraintEqualToAnchor:self.contentView.leadingAnchor |
45 constant:kMargin], | 54 constant:kMargin], |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // height. | 98 // height. |
90 [super layoutSubviews]; | 99 [super layoutSubviews]; |
91 } | 100 } |
92 | 101 |
93 - (void)prepareForReuse { | 102 - (void)prepareForReuse { |
94 self.textLabel.text = nil; | 103 self.textLabel.text = nil; |
95 self.detailTextLabel.text = nil; | 104 self.detailTextLabel.text = nil; |
96 } | 105 } |
97 | 106 |
98 @end | 107 @end |
OLD | NEW |