Bez popisu

PindanMessageCell.m 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // PindanMSGTableViewCell.m
  3. // FirstLink
  4. //
  5. // Created by Lemon on 15/4/27.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "PindanMessageCell.h"
  9. @interface PindanMessageCell ()
  10. @end
  11. @implementation PindanMessageCell
  12. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  13. [super setSelected:selected animated:animated];
  14. // Configure the view for the selected state
  15. }
  16. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. [self addAllSubViews];
  20. }
  21. return self;
  22. }
  23. #pragma mark - Generate Properties
  24. - (UIImageView *)photoView {
  25. if (!_photoView) {
  26. _photoView = [[UIImageView alloc] init];
  27. _photoView.layer.borderWidth = 1.0;//[UIScreen mainScreen].scale;
  28. _photoView.layer.borderColor = UIColorFromRGB(0xe5e5e5).CGColor;
  29. }
  30. return _photoView;
  31. }
  32. - (UILabel *)timeLabel {
  33. if (!_timeLabel) {
  34. _timeLabel = [[UILabel alloc] init];
  35. _timeLabel.font = [UIFont systemFontOfSize:13];
  36. _timeLabel.textColor = UIColorFromRGB(0x7a7a7a);
  37. // _timeLabel.backgroundColor = [UIColor redColor];
  38. }
  39. return _timeLabel;
  40. }
  41. - (UIImageView*)unreadView {
  42. if (!_unreadView) {
  43. _unreadView = [[UIImageView alloc] init];
  44. _unreadView.backgroundColor = UIColorFromRGB(0x00c8a9);
  45. _unreadView.layer.cornerRadius = 4;
  46. }
  47. return _unreadView;
  48. }
  49. - (UILabel *)titleLabel {
  50. if (!_titleLabel) {
  51. _titleLabel = [[UILabel alloc] init];
  52. _titleLabel.font = [UIFont systemFontOfSize:13];
  53. _titleLabel.textColor = UIColorFromRGB(0x333333);
  54. }
  55. return _titleLabel;
  56. }
  57. - (TTTAttributedLabel*)descLabel {
  58. if (!_descLabel) {
  59. _descLabel = [[TTTAttributedLabel alloc] init];
  60. _descLabel.font = [UIFont systemFontOfSize:14];
  61. _descLabel.textColor = UIColorFromRGB(0x333333);
  62. _descLabel.lineBreakMode = NSLineBreakByCharWrapping;
  63. _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
  64. _descLabel.numberOfLines = 0;
  65. // _descLabel.backgroundColor = [UIColor redColor];
  66. }
  67. return _descLabel;
  68. }
  69. - (UIButton *)detailButton {
  70. if (!_detailButton) {
  71. _detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
  72. [_detailButton setTitle:@"查看详情" forState:UIControlStateNormal];
  73. [_detailButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
  74. [_detailButton setTitleColor:UIColorFromRGB(0x999999)
  75. forState:UIControlStateNormal];
  76. _detailButton.layer.borderColor = [UIColor orangeColor].CGColor;
  77. _detailButton.userInteractionEnabled = NO;
  78. _detailButton.imageEdgeInsets = UIEdgeInsetsMake(0, -12, 0, 0);
  79. _detailButton.transform = CGAffineTransformMakeScale(-1.0, 1.0);
  80. _detailButton.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
  81. _detailButton.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
  82. [_detailButton setImage:[UIImage imageNamed:@"thin_right_arrow"] forState:UIControlStateNormal];
  83. }
  84. return _detailButton;
  85. }
  86. #pragma mark - Layout
  87. - (void)addAllSubViews {
  88. [self.contentView addSubview:self.photoView];
  89. [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.equalTo(self.contentView).offset(15);
  91. make.centerY.equalTo(self.contentView);
  92. make.size.mas_equalTo(CGSizeMake(75, 75));
  93. }];
  94. [self.contentView addSubview:self.unreadView];
  95. [self.unreadView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(self.photoView.mas_right).offset(-4);
  97. make.top.equalTo(self.photoView.mas_top).offset(-2);
  98. make.size.mas_equalTo(CGSizeMake(8, 8));
  99. }];
  100. [self.contentView addSubview:self.titleLabel];
  101. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.equalTo(self.photoView.mas_right).with.offset(15);
  103. make.right.equalTo(self.contentView).offset(-15);
  104. make.top.equalTo(self.contentView).offset(6);
  105. make.height.mas_equalTo(34);
  106. }];
  107. [self.contentView addSubview:self.descLabel];
  108. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.left.equalTo(self.photoView.mas_right).offset(15);
  110. make.right.equalTo(self.contentView).offset(-15);
  111. make.top.equalTo(self.titleLabel.mas_bottom).offset(0);
  112. }];
  113. self.descConstraint = [NSLayoutConstraint constraintWithItem:self.descLabel
  114. attribute:NSLayoutAttributeHeight
  115. relatedBy:NSLayoutRelationEqual
  116. toItem:self
  117. attribute:NSLayoutAttributeHeight
  118. multiplier:1.0
  119. constant:0];
  120. [self.contentView addSubview:self.timeLabel];
  121. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.equalTo(self.photoView.mas_right).offset(15);
  123. make.top.equalTo(self.descLabel.mas_bottom).offset(6);
  124. make.width.mas_greaterThanOrEqualTo(40);
  125. make.height.mas_equalTo(20);
  126. }];
  127. [self.contentView addSubview:self.detailButton];
  128. [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.right.equalTo(self.contentView).offset(-15);
  130. make.centerY.equalTo(self.timeLabel);
  131. make.width.mas_greaterThanOrEqualTo(80);
  132. make.height.mas_equalTo(36);
  133. }];
  134. }
  135. #pragma mark -
  136. - (void)setUnreadViewWith:(NSString *)status {
  137. if (!status) {
  138. self.unreadView.hidden = YES;
  139. }
  140. if ([status isEqualToString:@"1"]) {
  141. self.unreadView.hidden = NO;
  142. } else {
  143. self.unreadView.hidden = YES;
  144. }
  145. }
  146. - (void)layoutWithTitle:(BOOL)isWithTitle {
  147. if (isWithTitle) {
  148. [self.descLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  149. make.left.equalTo(self.photoView.mas_right).offset(15);
  150. make.right.equalTo(self.contentView).offset(-15);
  151. make.top.equalTo(self.titleLabel.mas_bottom).offset(0);
  152. }];
  153. } else {
  154. [self.descLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  155. make.left.equalTo(self.photoView.mas_right).offset(15);
  156. make.right.equalTo(self.contentView).offset(-15);
  157. make.top.equalTo(self.contentView).offset(18);
  158. }];
  159. }
  160. }
  161. #pragma mark - Helper
  162. + (CGFloat)titleHeightWith:(NSString *)title {
  163. return [FLStringHelper sizeOfAttributeString:title
  164. font:[UIFont systemFontOfSize:13]
  165. width:(UISCREENWIDTH - 15 - 75 - 2*15)
  166. maxRow:100].height;
  167. }
  168. + (CGFloat)cellHeightWith:(NSString *)title isWithTitle:(BOOL)isWithTitle {
  169. CGFloat offset = (isWithTitle ? 22 : 0);
  170. CGFloat otherHeight = (18 + offset + 6 + 20 + 16 + 1);
  171. CGFloat titleHeight = [PindanMessageCell titleHeightWith:title];
  172. return MAX(110, otherHeight + titleHeight);
  173. }
  174. @end