Sin descripción

SysMessageCell.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // SysMsgTableViewCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 14/12/26.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "SysMessageCell.h"
  9. @interface SysMessageCell ()
  10. @end
  11. @implementation SysMessageCell
  12. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  13. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. [self addAllSubviews];
  16. }
  17. return self;
  18. }
  19. #pragma mark - Property
  20. - (UILabel*)headLabel {
  21. if (!_headLabel) {
  22. _headLabel = [[UILabel alloc] init];
  23. _headLabel.font = [UIFont systemFontOfSize:15.0];
  24. _headLabel.textColor = UIColorFromRGB(0x999999);
  25. _headLabel.text = @"系统消息";
  26. }
  27. return _headLabel;
  28. }
  29. - (TTTAttributedLabel*)timeLabel {
  30. if (!_timeLabel) {
  31. _timeLabel = [[TTTAttributedLabel alloc] init];
  32. _timeLabel.font = [UIFont systemFontOfSize:13.0];
  33. _timeLabel.textColor = UIColorFromRGB(0x999999);
  34. _timeLabel.textAlignment = NSTextAlignmentRight;
  35. }
  36. return _timeLabel;
  37. }
  38. - (TTTAttributedLabel*)descLabel {
  39. if (!_descLabel) {
  40. _descLabel = [[TTTAttributedLabel alloc] init];
  41. _descLabel.font = [UIFont systemFontOfSize:14.0];
  42. _descLabel.textColor = UIColorFromRGB(0x333333);
  43. _descLabel.lineBreakMode = NSLineBreakByCharWrapping;
  44. _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
  45. _descLabel.numberOfLines = 0;
  46. }
  47. return _descLabel;
  48. }
  49. - (UIButton *)detailButton {
  50. if (!_detailButton) {
  51. _detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
  52. [_detailButton setTitle:@"查看详情 >" forState:UIControlStateNormal];
  53. [_detailButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
  54. [_detailButton setTitleColor:UIColorFromRGB(0x999999)
  55. forState:UIControlStateNormal];
  56. _detailButton.layer.borderColor = [UIColor orangeColor].CGColor;
  57. }
  58. return _detailButton;
  59. }
  60. - (UIView*)makeNewLine {
  61. UIView *view = [[UIView alloc] init];
  62. view.backgroundColor = UIColorFromRGB(0xe5e5e5);
  63. return view;
  64. }
  65. #pragma mark -
  66. - (void)addAllSubviews {
  67. WeakSelf(weakSelf);
  68. [self.contentView addSubview:self.headLabel];
  69. [self.headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.equalTo(weakSelf.contentView).with.offset(15);
  71. make.top.equalTo(weakSelf.contentView).with.offset(8);
  72. make.size.mas_equalTo(CGSizeMake(75, 24));
  73. }];
  74. [self.contentView addSubview:self.timeLabel];
  75. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.right.equalTo(weakSelf.contentView).with.offset(-20);
  77. make.centerY.equalTo(weakSelf.headLabel.mas_centerY);
  78. make.width.mas_greaterThanOrEqualTo(40);
  79. make.height.mas_equalTo(20);
  80. }];
  81. UIView *line = [self makeNewLine];
  82. [self.contentView addSubview:line];
  83. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(weakSelf.contentView);
  85. make.right.equalTo(weakSelf.contentView);
  86. make.top.equalTo(weakSelf.headLabel.mas_bottom).with.offset(8);
  87. make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  88. }];
  89. [self.contentView addSubview:self.detailButton];
  90. [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.bottom.equalTo(weakSelf.contentView).with.offset(-2);
  92. make.right.equalTo(weakSelf.contentView).with.offset(-15);
  93. make.width.mas_equalTo(80);
  94. make.height.mas_equalTo(36);
  95. }];
  96. [self.contentView addSubview:self.descLabel];
  97. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.equalTo(weakSelf.contentView).with.offset(15);
  99. make.right.equalTo(weakSelf.contentView).with.offset(-15);
  100. make.top.equalTo(line.mas_bottom).with.offset(13);
  101. make.bottom.equalTo(weakSelf.contentView).with.offset(-0);
  102. }];
  103. }
  104. #pragma mark - Help Method
  105. + (CGFloat)cellHeightWith:(FKAppMessage*)item {
  106. if (!item.content) {
  107. return 44;
  108. }
  109. CGFloat height;
  110. int maxRow;
  111. // if (item.targetURL.length > 0) {
  112. // maxRow = 2;
  113. // height = (8 + 24 + 8 + 10 + 36 + 2 + 1);
  114. // } else {
  115. height = (8 + 24 + 8 + 13 + 36 + 2 + 1);
  116. maxRow = 100;
  117. // }
  118. CGSize size = [FLStringHelper sizeOfAttributeString:item.content
  119. font:[UIFont systemFontOfSize:14.0]
  120. width:(UISCREENWIDTH - 2*15)
  121. maxRow:maxRow];
  122. height += size.height;
  123. return height;
  124. }
  125. @end