YRMsgMainCell.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // YRMsgMainCell.m
  3. // UU_Ent
  4. //
  5. // Created by liujl on 2019/4/29.
  6. // Copyright © 2019 UAS. All rights reserved.
  7. //
  8. #import "YRMsgMainCell.h"
  9. @interface YRMsgMainCell()
  10. @property(strong,nonatomic)UIImageView *iconView;
  11. @property(strong,nonatomic)UILabel *remindLabel;
  12. @property(strong,nonatomic)UILabel *titleLabel;
  13. @property(strong,nonatomic)UILabel *subTitLabel;
  14. @end
  15. @implementation YRMsgMainCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier{
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. [self setUpUI];
  19. }
  20. return self;
  21. }
  22. -(void)setUpUI{
  23. [self.contentView addSubview:self.iconView];
  24. [self.iconView addSubview:self.remindLabel];
  25. [self.contentView addSubview:self.titleLabel];
  26. [self.contentView addSubview:self.subTitLabel];
  27. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.equalTo(self.contentView).offset(16);
  29. make.left.equalTo(self.contentView).offset(18);
  30. make.bottom.equalTo(self.contentView).offset(-16);
  31. make.width.mas_equalTo(34);
  32. }];
  33. [self.remindLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self.iconView).offset(-8);
  35. make.right.equalTo(self.iconView).offset(8);
  36. make.width.height.mas_equalTo(16);
  37. }];
  38. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.equalTo(self.contentView).offset(14);
  40. make.left.equalTo(self.iconView.mas_right).offset(10);
  41. make.height.mas_equalTo(20);
  42. make.right.equalTo(self.contentView).offset(-20);
  43. }];
  44. [self.subTitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self.titleLabel.mas_bottom).offset(6);
  46. make.height.mas_greaterThanOrEqualTo(@10);
  47. make.left.equalTo(self.iconView.mas_right).offset(10);
  48. make.right.equalTo(self.contentView).offset(-20);
  49. }];
  50. }
  51. -(void)setModel:(YRMsgMainModel *)model{
  52. _model = model;
  53. self.iconView.image = [UIImage imageNamed:model.icon];
  54. self.titleLabel.text = model.name;
  55. self.subTitLabel.text = @"这是副标题";
  56. if (model.remindCount > 0) {
  57. self.remindLabel.hidden = NO;
  58. self.remindLabel.text = [NSString stringWithFormat:@"%ld",(long)model.remindCount];
  59. }else{
  60. self.remindLabel.hidden = YES;
  61. }
  62. }
  63. #pragma mark - lazy
  64. -(UIImageView *)iconView{
  65. if (!_iconView) {
  66. _iconView = [[UIImageView alloc]init];
  67. }
  68. return _iconView;
  69. }
  70. -(UILabel *)remindLabel{
  71. if (!_remindLabel) {
  72. _remindLabel = [UILabel new];
  73. _remindLabel.font = [UIFont systemFontOfSize:9];
  74. _remindLabel.textAlignment = NSTextAlignmentCenter;
  75. _remindLabel.textColor = [UIColor whiteColor];
  76. _remindLabel.backgroundColor = [UIColor redColor];
  77. _remindLabel.layer.cornerRadius = 8;
  78. _remindLabel.layer.masksToBounds = YES;
  79. }
  80. return _remindLabel;
  81. }
  82. -(UILabel *)titleLabel{
  83. if (!_titleLabel) {
  84. _titleLabel = [UILabel new];
  85. }
  86. return _titleLabel;
  87. }
  88. -(UILabel *)subTitLabel{
  89. if (!_subTitLabel) {
  90. _subTitLabel = [UILabel new];
  91. _subTitLabel.font = [UIFont systemFontOfSize:11];
  92. _subTitLabel.textColor = [UIColor grayColor];
  93. }
  94. return _subTitLabel;
  95. }
  96. @end