No Description

SessionListCell.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // SessionListCell.m
  3. // FirstLink
  4. //
  5. // Created by Lemon on 15/4/20.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "SessionListCell.h"
  9. @interface SessionListCell ()
  10. @end
  11. @implementation SessionListCell
  12. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  13. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. self.selectionStyle = UITableViewCellSelectionStyleNone;
  16. self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  17. [self layoutAllComponents];
  18. }
  19. return self;
  20. }
  21. #pragma mark - Generate Properties
  22. - (APAvatarImageView *)iconView {
  23. if (!_iconView) {
  24. _iconView = [[APAvatarImageView alloc] init];
  25. _iconView.borderColor = [UIColor whiteColor];
  26. }
  27. return _iconView;
  28. }
  29. - (UILabel *)tagLabel {
  30. if (!_tagLabel) {
  31. _tagLabel = [[UILabel alloc] init];
  32. _tagLabel.font = [UIFont systemFontOfSize:16.0];
  33. _tagLabel.textColor = UIColorFromRGB(0x333333);
  34. }
  35. return _tagLabel;
  36. }
  37. - (UILabel *)unreadLabel {
  38. if (!_unreadLabel) {
  39. _unreadLabel = [[UILabel alloc] init];
  40. _unreadLabel.textColor = [UIColor whiteColor];
  41. _unreadLabel.backgroundColor = UIColorFromRGB(0xff676b);
  42. _unreadLabel.textAlignment = NSTextAlignmentCenter;
  43. _unreadLabel.font = [UIFont systemFontOfSize:11];
  44. _unreadLabel.layer.cornerRadius = 8;
  45. _unreadLabel.clipsToBounds = YES;
  46. }
  47. return _unreadLabel;
  48. }
  49. - (UILabel *)messageLabel {
  50. if (!_messageLabel) {
  51. _messageLabel = [[UILabel alloc] init];
  52. _messageLabel.font = [UIFont systemFontOfSize:14.0];
  53. _messageLabel.textColor = UIColorFromRGB(0xcccccc);
  54. _messageLabel.textAlignment = NSTextAlignmentRight;
  55. }
  56. return _messageLabel;
  57. }
  58. - (APAvatarImageView *)headView {
  59. if (!_headView) {
  60. _headView = [[APAvatarImageView alloc] init];
  61. _headView.borderColor = [UIColor whiteColor];
  62. _headView.borderWidth = 0;
  63. _headView.cornerRadius = 3;
  64. }
  65. return _headView;
  66. }
  67. #pragma mark - Layout
  68. - (void)layoutAllComponents {
  69. WeakSelf(weakSelf);
  70. [self.contentView addSubview:self.iconView];
  71. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(weakSelf.contentView).with.offset(15);
  73. make.centerY.equalTo(weakSelf.contentView);
  74. make.size.mas_equalTo(CGSizeMake(35, 35));
  75. }];
  76. [self.contentView addSubview:self.tagLabel];
  77. [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(weakSelf.iconView.mas_right).with.offset(6);
  79. make.centerY.equalTo(weakSelf.contentView);
  80. make.size.mas_equalTo(CGSizeMake(66, 30));
  81. }];
  82. [self.contentView addSubview:self.unreadLabel];
  83. [self.unreadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(weakSelf.iconView.mas_right).with.offset(-8);
  85. make.top.equalTo(weakSelf.iconView.mas_top).with.offset(-4);
  86. make.width.mas_greaterThanOrEqualTo(16);
  87. make.height.mas_equalTo(16);
  88. }];
  89. [self.contentView addSubview:self.headView];
  90. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.equalTo(weakSelf.contentView).with.offset(-16);
  92. make.centerY.equalTo(weakSelf.contentView);
  93. make.size.mas_equalTo(CGSizeMake(32, 32));
  94. }];
  95. [self.contentView addSubview:self.messageLabel];
  96. [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.equalTo(weakSelf.tagLabel.mas_right).with.offset(10);
  98. make.right.equalTo(weakSelf.headView.mas_left).with.offset(-10);
  99. make.centerY.equalTo(weakSelf.contentView);
  100. make.height.mas_equalTo(30);
  101. }];
  102. }
  103. #pragma mark -
  104. - (void)setCellType:(SessionListCellType)cellType {
  105. _cellType = cellType;
  106. switch (cellType) {
  107. case SessionListCellTypeDefault: {
  108. self.messageLabel.hidden = YES;
  109. self.headView.hidden = YES;
  110. break;
  111. }
  112. case SessionListCellTypeMessage: {
  113. self.messageLabel.hidden = NO;
  114. self.headView.hidden = NO;
  115. break;
  116. }
  117. default:
  118. break;
  119. }
  120. }
  121. - (void)setUnreadNumberString:(NSString *)value {
  122. if (value.intValue <= 0) {
  123. self.unreadLabel.hidden = YES;
  124. } else {
  125. self.unreadLabel.hidden = NO;
  126. self.unreadLabel.text = value;
  127. }
  128. }
  129. - (void)setMessageText:(NSString *)text {
  130. if (!text || text.length == 0) {
  131. self.messageLabel.hidden = YES;
  132. } else {
  133. self.messageLabel.hidden = NO;
  134. self.messageLabel.text = text;
  135. }
  136. }
  137. @end