EaseMessageTimeCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /************************************************************
  2. * * Hyphenate CONFIDENTIAL
  3. * __________________
  4. * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
  5. *
  6. * NOTICE: All information contained herein is, and remains
  7. * the property of Hyphenate Inc.
  8. * Dissemination of this information or reproduction of this material
  9. * is strictly forbidden unless prior written permission is obtained
  10. * from Hyphenate Inc.
  11. */
  12. #import "EaseMessageTimeCell.h"
  13. CGFloat const EaseMessageTimeCellPadding = 5;
  14. @interface EaseMessageTimeCell()
  15. @property (strong, nonatomic) UILabel *titleLabel;
  16. @end
  17. @implementation EaseMessageTimeCell
  18. + (void)initialize
  19. {
  20. // UIAppearance Proxy Defaults
  21. EaseMessageTimeCell *cell = [self appearance];
  22. cell.titleLabelColor = [UIColor grayColor];
  23. cell.titleLabelFont = [UIFont systemFontOfSize:12];
  24. }
  25. - (instancetype)initWithStyle:(UITableViewCellStyle)style
  26. reuseIdentifier:(NSString *)reuseIdentifier
  27. {
  28. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  29. if (self) {
  30. self.backgroundColor = [UIColor clearColor];
  31. [self _setupSubview];
  32. }
  33. return self;
  34. }
  35. #pragma mark - setup subviews
  36. - (void)_setupSubview
  37. {
  38. _titleLabel = [[UILabel alloc] init];
  39. _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  40. _titleLabel.textAlignment = NSTextAlignmentCenter;
  41. _titleLabel.backgroundColor = [UIColor clearColor];
  42. _titleLabel.textColor = _titleLabelColor;
  43. _titleLabel.font = _titleLabelFont;
  44. [self.contentView addSubview:_titleLabel];
  45. [self _setupTitleLabelConstraints];
  46. }
  47. #pragma mark - Setup Constraints
  48. - (void)_setupTitleLabelConstraints
  49. {
  50. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:EaseMessageTimeCellPadding]];
  51. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-EaseMessageTimeCellPadding]];
  52. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
  53. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-EaseMessageTimeCellPadding]];
  54. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:EaseMessageTimeCellPadding]];
  55. }
  56. #pragma mark - setter
  57. - (void)setTitle:(NSString *)title
  58. {
  59. _title = title;
  60. _titleLabel.text = _title;
  61. }
  62. - (void)setTitleLabelFont:(UIFont *)titleLabelFont
  63. {
  64. _titleLabelFont = titleLabelFont;
  65. _titleLabel.font = _titleLabelFont;
  66. }
  67. - (void)setTitleLabelColor:(UIColor *)titleLabelColor
  68. {
  69. _titleLabelColor = titleLabelColor;
  70. _titleLabel.textColor = _titleLabelColor;
  71. }
  72. #pragma mark - public
  73. + (NSString *)cellIdentifier
  74. {
  75. return @"MessageTimeCell";
  76. }
  77. @end