host_setup_view_cell.mm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #import "remoting/ios/app/host_setup_view_cell.h"
  5. #import <MaterialComponents/MaterialTypography.h>
  6. #import "remoting/ios/app/remoting_theme.h"
  7. #import "remoting/ios/app/view_utils.h"
  8. #if !defined(__has_feature) || !__has_feature(objc_arc)
  9. #error "This file requires ARC support."
  10. #endif
  11. static const CGFloat kNumberIconPadding = 16.f;
  12. static const CGFloat kNumberIconSize = 45.f;
  13. static const CGFloat kCellXPadding = 22.f;
  14. static const CGFloat kCellYPadding = 28.f;
  15. @interface HostSetupViewCell () {
  16. UIView* _numberContainerView;
  17. UILabel* _numberLabel;
  18. UILabel* _contentLabel;
  19. }
  20. @end
  21. @implementation HostSetupViewCell
  22. - (instancetype)initWithStyle:(UITableViewCellStyle)style
  23. reuseIdentifier:(NSString*)reuseIdentifier {
  24. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  25. [self commonInit];
  26. }
  27. return self;
  28. }
  29. - (void)commonInit {
  30. self.isAccessibilityElement = YES;
  31. self.backgroundColor = RemotingTheme.setupListBackgroundColor;
  32. _numberContainerView = [[UIView alloc] init];
  33. _numberLabel = [[UILabel alloc] init];
  34. _contentLabel = [[UILabel alloc] init];
  35. _numberContainerView.translatesAutoresizingMaskIntoConstraints = NO;
  36. _numberLabel.translatesAutoresizingMaskIntoConstraints = NO;
  37. _contentLabel.translatesAutoresizingMaskIntoConstraints = NO;
  38. _contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  39. _contentLabel.numberOfLines = 0;
  40. _numberContainerView.backgroundColor = RemotingTheme.hostOnlineColor;
  41. _numberLabel.textColor = RemotingTheme.setupListNumberColor;
  42. _contentLabel.textColor = RemotingTheme.setupListTextColor;
  43. _numberLabel.font = MDCTypography.titleFont;
  44. _contentLabel.font = MDCTypography.subheadFont;
  45. _numberContainerView.layer.cornerRadius = kNumberIconSize / 2.f;
  46. [self.contentView addSubview:_numberContainerView];
  47. [self.contentView addSubview:_contentLabel];
  48. [_numberContainerView addSubview:_numberLabel];
  49. UILayoutGuide* safeAreaLayoutGuide =
  50. remoting::SafeAreaLayoutGuideForView(self.contentView);
  51. NSArray* constraints = @[
  52. [_numberContainerView.leadingAnchor
  53. constraintEqualToAnchor:safeAreaLayoutGuide.leadingAnchor
  54. constant:kCellXPadding],
  55. [_numberContainerView.centerYAnchor
  56. constraintEqualToAnchor:_contentLabel.centerYAnchor],
  57. [_numberContainerView.widthAnchor
  58. constraintEqualToConstant:kNumberIconSize],
  59. [_numberContainerView.heightAnchor
  60. constraintEqualToConstant:kNumberIconSize],
  61. [_numberLabel.centerXAnchor
  62. constraintEqualToAnchor:_numberContainerView.centerXAnchor],
  63. [_numberLabel.centerYAnchor
  64. constraintEqualToAnchor:_numberContainerView.centerYAnchor],
  65. [_contentLabel.leadingAnchor
  66. constraintEqualToAnchor:_numberContainerView.trailingAnchor
  67. constant:kNumberIconPadding],
  68. [_contentLabel.trailingAnchor
  69. constraintEqualToAnchor:safeAreaLayoutGuide.trailingAnchor
  70. constant:-kCellXPadding],
  71. [_contentLabel.topAnchor
  72. constraintEqualToAnchor:safeAreaLayoutGuide.topAnchor],
  73. [_contentLabel.bottomAnchor
  74. constraintEqualToAnchor:safeAreaLayoutGuide.bottomAnchor
  75. constant:-kCellYPadding],
  76. [_contentLabel.heightAnchor
  77. constraintGreaterThanOrEqualToAnchor:_numberContainerView.heightAnchor],
  78. ];
  79. [NSLayoutConstraint activateConstraints:constraints];
  80. }
  81. - (void)setContentText:(NSString*)text number:(NSInteger)number {
  82. self.accessibilityLabel = text;
  83. _contentLabel.text = text;
  84. _numberLabel.text = [@(number) stringValue];
  85. }
  86. @end