TUIGroupNoticeCell.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // TUIGroupNoticeCell.m
  3. // TUIGroup
  4. //
  5. // Created by harvy on 2022/1/11.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIGroupNoticeCell.h"
  9. #import <TUICore/TUIThemeManager.h>
  10. #import <TIMCommon/TIMDefine.h>
  11. @implementation TUIGroupNoticeCell
  12. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  13. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  14. [self setupViews];
  15. }
  16. return self;
  17. }
  18. - (void)setupViews {
  19. self.backgroundColor = TIMCommonDynamicColor(@"form_bg_color", @"#FFFFFF");
  20. self.contentView.backgroundColor = TIMCommonDynamicColor(@"form_bg_color", @"#FFFFFF");
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  23. [self.contentView addSubview:self.nameLabel];
  24. [self.contentView addSubview:self.descLabel];
  25. UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
  26. tapRecognizer.delegate = self;
  27. tapRecognizer.cancelsTouchesInView = NO;
  28. [self.contentView addGestureRecognizer:tapRecognizer];
  29. }
  30. - (void)tapGesture:(UIGestureRecognizer *)gesture {
  31. if (self.cellData.selector && self.cellData.target) {
  32. if ([self.cellData.target respondsToSelector:self.cellData.selector]) {
  33. #pragma clang diagnostic push
  34. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  35. [self.cellData.target performSelector:self.cellData.selector];
  36. #pragma clang diagnostic pop
  37. }
  38. }
  39. }
  40. - (void)setCellData:(TUIGroupNoticeCellData *)cellData {
  41. _cellData = cellData;
  42. self.nameLabel.text = cellData.name;
  43. self.descLabel.text = cellData.desc;
  44. // tell constraints they need updating
  45. [self setNeedsUpdateConstraints];
  46. // update constraints now so we can animate the change
  47. [self updateConstraintsIfNeeded];
  48. [self layoutIfNeeded];
  49. }
  50. + (BOOL)requiresConstraintBasedLayout {
  51. return YES;
  52. }
  53. // this is Apple's recommended place for adding/updating constraints
  54. - (void)updateConstraints {
  55. [super updateConstraints];
  56. [self.nameLabel sizeToFit];
  57. [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  58. make.leading.mas_equalTo(20);
  59. make.top.mas_equalTo(12);
  60. make.trailing.mas_lessThanOrEqualTo(self.contentView).mas_offset(-20);
  61. make.size.mas_equalTo(self.nameLabel.frame.size);
  62. }];
  63. [self.descLabel sizeToFit];
  64. [self.descLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  65. make.leading.mas_equalTo(self.nameLabel);
  66. make.top.mas_equalTo(self.nameLabel.mas_bottom).mas_offset(4);
  67. make.trailing.mas_lessThanOrEqualTo(self.contentView).mas_offset(-30);
  68. make.size.mas_equalTo(self.descLabel.frame.size);
  69. }];
  70. }
  71. - (void)layoutSubviews {
  72. [super layoutSubviews];
  73. }
  74. - (UILabel *)nameLabel {
  75. if (_nameLabel == nil) {
  76. _nameLabel = [[UILabel alloc] init];
  77. _nameLabel.text = @"";
  78. _nameLabel.textColor = TIMCommonDynamicColor(@"form_key_text_color", @"#888888");
  79. _nameLabel.font = [UIFont systemFontOfSize:16.0];
  80. }
  81. return _nameLabel;
  82. }
  83. - (UILabel *)descLabel {
  84. if (_descLabel == nil) {
  85. _descLabel = [[UILabel alloc] init];
  86. _descLabel.text = @"neirong";
  87. _descLabel.textColor = TIMCommonDynamicColor(@"form_subtitle_color", @"#BBBBBB");
  88. _descLabel.font = [UIFont systemFontOfSize:12.0];
  89. }
  90. return _descLabel;
  91. }
  92. @end