BGSystemMsgImageCell.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // BGSystemMsgImageCell.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/12/16.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "BGSystemMsgImageCell.h"
  9. #import "UITableViewCell+HYBMasonryAutoCellHeight.h"
  10. @interface BGSystemMsgImageCell ()
  11. @property(nonatomic, strong) UILabel *timeLabel;
  12. @property (nonatomic,strong)UIView *bgView;
  13. @property(nonatomic, strong) UIImageView *coverImageView;
  14. @property(nonatomic, strong) UILabel *titleLabel;
  15. @property(nonatomic, strong) UILabel *contentLabel;
  16. @end
  17. static NSString *const image_name_bg = @"dy_msg_bg";
  18. @implementation BGSystemMsgImageCell
  19. //
  20. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  21. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  22. [self setUpView];
  23. }
  24. return self;
  25. }
  26. -(void)setUpView{
  27. _timeLabel= ({
  28. UILabel * label = [[UILabel alloc]init];
  29. label.textColor = kAppGrayColor1;
  30. label.font = [UIFont systemFontOfSize:16];
  31. label;
  32. });
  33. _bgView=({
  34. UIView *view=[[UIView alloc]init];
  35. // view.backgroundColor = kRedColor;
  36. // view.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
  37. view.layer.cornerRadius = 2;
  38. view.layer.shadowColor = [UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:0.5].CGColor;
  39. view.layer.shadowOffset = CGSizeMake(0,0);
  40. view.layer.shadowOpacity = 1;
  41. view.layer.shadowRadius = 6;
  42. view;
  43. });
  44. _coverImageView = ({
  45. UIImageView *imageView = [[UIImageView alloc] init];
  46. // imageView.image = [UIImage imageNamed:image_name_bg];
  47. // imageView.contentMode = UIViewContentModeScaleToFill;
  48. imageView;
  49. });
  50. _titleLabel= ({
  51. UILabel * label = [[UILabel alloc]init];
  52. label.textColor = kAppGrayColor1;
  53. // label.backgroundColor = kBlackColor;
  54. label.font = [UIFont boldSystemFontOfSize:16];
  55. label.numberOfLines = 0;
  56. label;
  57. });
  58. _contentLabel= ({
  59. UILabel * label = [[UILabel alloc]init];
  60. label.textColor = kAppGrayColor2;
  61. label.font = [UIFont systemFontOfSize:14];
  62. label.numberOfLines = 0;
  63. label.textAlignment = NSTextAlignmentRight;
  64. label;
  65. });
  66. [self.contentView addSubview:_timeLabel];
  67. [self.contentView addSubview:_bgView];
  68. [_bgView addSubview:_titleLabel];
  69. [_bgView addSubview:_contentLabel];
  70. [_bgView addSubview:_coverImageView];
  71. self.hyb_lastViewInCell = _bgView;
  72. self.hyb_bottomOffsetToCell = 10;
  73. }
  74. - (void)layoutSubviews {
  75. [super layoutSubviews];
  76. [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.mas_equalTo(10);
  78. make.centerX.mas_equalTo(0);
  79. }];
  80. [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.top.mas_equalTo(0);
  82. make.left.mas_equalTo(0);
  83. make.right.mas_equalTo(0);
  84. make.height.mas_equalTo(kRealValue(143));
  85. }];
  86. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.top.equalTo(_coverImageView.mas_bottom).offset(8);
  88. make.left.mas_equalTo(18);
  89. // make.centerX.mas_equalTo(0);
  90. }];
  91. // [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. // make.top.equalTo(_titleLabel.mas_bottom).offset(8);
  93. // make.left.mas_equalTo(18);
  94. // make.centerX.mas_equalTo(0);
  95. // make.bottom.mas_equalTo(-20);
  96. //
  97. // }];
  98. [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  99. // make.top.equalTo(_titleLabel.mas_top);
  100. make.right.mas_equalTo(-18);
  101. make.centerY.mas_equalTo(_titleLabel);
  102. make.bottom.mas_equalTo(-20);
  103. }];
  104. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.top.equalTo(_timeLabel.mas_bottom).offset(8);
  106. make.left.mas_equalTo(11);
  107. make.centerX.mas_equalTo(0);
  108. }];
  109. }
  110. - (void)setModel:(BGSystemMsgModel *)model{
  111. _timeLabel.text = model.addtime;
  112. _titleLabel.text = model.title;
  113. _contentLabel.text = model.content;
  114. [_coverImageView sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:kDefaultPreloadImgRectangle];
  115. }
  116. @end