OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
nternal_cell.h" | |
6 | |
7 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
8 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | |
9 | |
10 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
11 #error "This file requires ARC support." | |
12 #endif | |
13 | |
14 namespace { | |
15 const CGFloat kFaviconImageSize = 50; | |
16 const CGFloat kFontSize = 10; | |
17 } | |
18 | |
19 @implementation ContentSuggestionsFaviconInternalCell | |
20 | |
21 @synthesize faviconView = _faviconView; | |
22 @synthesize titleLabel = _titleLabel; | |
23 | |
24 - (instancetype)initWithFrame:(CGRect)frame { | |
25 self = [super initWithFrame:frame]; | |
26 if (self) { | |
27 _faviconView = [[UIImageView alloc] init]; | |
28 _titleLabel = [[UILabel alloc] init]; | |
29 _titleLabel.numberOfLines = 2; | |
30 _titleLabel.font = [[MDCTypography fontLoader] lightFontOfSize:kFontSize]; | |
31 _titleLabel.textAlignment = NSTextAlignmentCenter; | |
32 | |
33 _faviconView.translatesAutoresizingMaskIntoConstraints = NO; | |
34 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | |
35 [self.contentView addSubview:_faviconView]; | |
36 [self.contentView addSubview:_titleLabel]; | |
37 | |
38 ApplyVisualConstraints( | |
39 @[ @"V:|-[image]-[title]-|" ], | |
40 @{ @"image" : _faviconView, | |
41 @"title" : _titleLabel }); | |
42 | |
43 [NSLayoutConstraint activateConstraints:@[ | |
44 [_faviconView.centerXAnchor | |
45 constraintEqualToAnchor:self.contentView.centerXAnchor], | |
46 [_titleLabel.leadingAnchor | |
47 constraintEqualToAnchor:self.contentView.leadingAnchor], | |
48 [_titleLabel.trailingAnchor | |
49 constraintEqualToAnchor:self.contentView.trailingAnchor], | |
50 [_faviconView.widthAnchor constraintEqualToConstant:kFaviconImageSize], | |
51 [_faviconView.heightAnchor | |
52 constraintEqualToAnchor:_faviconView.widthAnchor], | |
53 ]]; | |
54 } | |
55 return self; | |
56 } | |
57 | |
58 #pragma mark - UICollectionReusableView | |
59 | |
60 - (void)prepareForReuse { | |
61 [super prepareForReuse]; | |
62 self.faviconView.image = nil; | |
63 self.titleLabel.text = nil; | |
64 } | |
65 | |
66 + (NSString*)reuseIdentifier { | |
67 return @"faviconInternalCell"; | |
68 } | |
69 | |
70 @end | |
OLD | NEW |