OLD | NEW |
(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/suggestions/suggestions_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 @implementation SuggestionsItem { |
| 15 NSString* _title; |
| 16 NSString* _subtitle; |
| 17 } |
| 18 |
| 19 - (instancetype)initWithType:(NSInteger)type |
| 20 title:(NSString*)title |
| 21 subtitle:(NSString*)subtitle { |
| 22 self = [super initWithType:type]; |
| 23 if (self) { |
| 24 self.cellClass = [SuggestionsCell class]; |
| 25 _title = title; |
| 26 _subtitle = subtitle; |
| 27 } |
| 28 return self; |
| 29 } |
| 30 |
| 31 - (void)configureCell:(SuggestionsCell*)cell { |
| 32 [super configureCell:cell]; |
| 33 cell.title = _title; |
| 34 cell.detailText = _subtitle; |
| 35 } |
| 36 |
| 37 @end |
| 38 |
| 39 @implementation SuggestionsCell { |
| 40 UIButton* _titleButton; |
| 41 UILabel* _detailTextLabel; |
| 42 } |
| 43 |
| 44 @synthesize title = _title; |
| 45 @synthesize detailText = _detailText; |
| 46 |
| 47 - (instancetype)initWithFrame:(CGRect)frame { |
| 48 self = [super initWithFrame:frame]; |
| 49 if (self) { |
| 50 MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance]; |
| 51 _titleButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 52 _titleButton.titleLabel.font = [fontLoader mediumFontOfSize:16]; |
| 53 _titleButton.titleLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 54 [_titleButton addTarget:nil |
| 55 action:@selector(buttonPressed) |
| 56 forControlEvents:UIControlEventTouchUpInside]; |
| 57 |
| 58 _detailTextLabel = [[UILabel alloc] init]; |
| 59 _detailTextLabel.font = [fontLoader mediumFontOfSize:14]; |
| 60 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 61 |
| 62 UIStackView* labelsStack = [[UIStackView alloc] |
| 63 initWithArrangedSubviews:@[ _titleButton, _detailTextLabel ]]; |
| 64 labelsStack.axis = UILayoutConstraintAxisVertical; |
| 65 |
| 66 [self.contentView addSubview:labelsStack]; |
| 67 labelsStack.layoutMarginsRelativeArrangement = YES; |
| 68 labelsStack.layoutMargins = UIEdgeInsetsMake(16, 16, 16, 16); |
| 69 labelsStack.alignment = UIStackViewAlignmentCenter; |
| 70 |
| 71 labelsStack.translatesAutoresizingMaskIntoConstraints = NO; |
| 72 [NSLayoutConstraint activateConstraints:@[ |
| 73 [self.contentView.leadingAnchor |
| 74 constraintEqualToAnchor:labelsStack.leadingAnchor], |
| 75 [self.contentView.trailingAnchor |
| 76 constraintEqualToAnchor:labelsStack.trailingAnchor], |
| 77 [self.contentView.topAnchor |
| 78 constraintEqualToAnchor:labelsStack.topAnchor], |
| 79 [self.contentView.bottomAnchor |
| 80 constraintEqualToAnchor:labelsStack.bottomAnchor] |
| 81 |
| 82 ]]; |
| 83 |
| 84 self.backgroundColor = [UIColor whiteColor]; |
| 85 } |
| 86 return self; |
| 87 } |
| 88 |
| 89 #pragma mark - Properties |
| 90 |
| 91 - (void)setTitle:(NSString*)title { |
| 92 [_titleButton setTitle:title forState:UIControlStateNormal]; |
| 93 _title = title; |
| 94 } |
| 95 |
| 96 - (void)setDetailText:(NSString*)detailText { |
| 97 _detailTextLabel.text = detailText; |
| 98 _detailText = detailText; |
| 99 } |
| 100 |
| 101 @end |
OLD | NEW |