TXGroupNoticeMessageContentView.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // TXGroupNoticeMessageContentView.m
  3. // TUIChat
  4. //
  5. // Created by 王智 on 2024/8/30.
  6. //
  7. #import "TXGroupNoticeMessageContentView.h"
  8. #import "Masonry.h"
  9. #import "UIImageView+WebCache.h"
  10. #import "TUIDefine.h"
  11. #define TXHexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  12. @interface TXGroupNoticeMessageContentView ()
  13. @property (nonatomic, strong) UIImageView *noticeIcon;
  14. @property (nonatomic, strong) UILabel *noticedTopTitle;
  15. @property (nonatomic, strong) UILabel *msgTitleLabel;
  16. @property (nonatomic, strong) UILabel *msgContentLabel;
  17. @end
  18. @implementation TXGroupNoticeMessageContentView
  19. + (instancetype)shareIntance {
  20. return [[TXGroupNoticeMessageContentView alloc] init];
  21. }
  22. - (instancetype)init {
  23. self = [super init];
  24. if (self) {
  25. [self configUI];
  26. }
  27. return self;
  28. }
  29. - (void)configUI {
  30. self.backgroundColor = [UIColor whiteColor];
  31. self.layer.cornerRadius = 10.0f;
  32. [self addSubview:self.noticeIcon];
  33. [self.noticeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.mas_equalTo(self.mas_left).offset(12);
  35. make.top.mas_equalTo(self.mas_top).offset(13);
  36. make.width.mas_equalTo(18);
  37. make.height.mas_equalTo(18);
  38. }];
  39. [self addSubview:self.noticedTopTitle];
  40. [self.noticedTopTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(self.noticeIcon.mas_right).offset(6);
  42. make.height.mas_equalTo(21);
  43. make.top.mas_equalTo(self.mas_top).offset(11);
  44. }];
  45. [self addSubview:self.msgTitleLabel];
  46. [self.msgTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.mas_equalTo(self.mas_left).offset(12);
  48. make.right.mas_equalTo(self.mas_right).offset(-12);
  49. make.top.mas_equalTo(self.noticedTopTitle.mas_bottom).offset(11);
  50. make.height.mas_equalTo(21);
  51. }];
  52. [self addSubview:self.msgContentLabel];
  53. [self.msgContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.mas_equalTo(self.mas_left).offset(12);
  55. make.right.mas_equalTo(self.mas_right).offset(-12);
  56. make.top.mas_equalTo(self.msgTitleLabel.mas_bottom);
  57. }];
  58. }
  59. - (void)configCellWithMsgTitle:(NSString *)title content:(NSString *)content {
  60. self.msgTitleLabel.text = [self returnNoNullStringWithString:title];
  61. if (![self isEmptyString:content]) {
  62. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f],NSForegroundColorAttributeName:TXHexRGB(0x333333)}];
  63. self.msgContentLabel.attributedText = attr;
  64. }
  65. else {
  66. self.msgContentLabel.text = @"";
  67. }
  68. }
  69. - (NSString *)returnNoNullStringWithString:(NSString *)string {
  70. if (string == nil || string.length == 0) {
  71. return @"";
  72. }
  73. return string;
  74. }
  75. - (NSString *)getUrlEndcodeString:(NSString *)string {
  76. NSString *url = [string stringByRemovingPercentEncoding];
  77. return [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];;
  78. }
  79. - (BOOL)isEmptyString:(NSString *)str {
  80. if (str == nil || str.length == 0) {
  81. return YES;
  82. }
  83. return NO;
  84. }
  85. #pragma mark ------ notice content view
  86. - (UIImageView *)noticeIcon {
  87. if (!_noticeIcon) {
  88. _noticeIcon = [[UIImageView alloc] init];
  89. [_noticeIcon setImage:TUIChatBundleThemeImage(@"chat_custom_order_message_img", @"TXGroupNoticeMessageIcon")];
  90. }
  91. return _noticeIcon;
  92. }
  93. - (UILabel *)noticedTopTitle {
  94. if (!_noticedTopTitle) {
  95. _noticedTopTitle = [[UILabel alloc] init];
  96. _noticedTopTitle.textColor = TXHexRGB(0x19B396);
  97. _noticedTopTitle.font = [UIFont systemFontOfSize:15.0f weight:UIFontWeightRegular];
  98. _noticedTopTitle.text = @"群公告";
  99. }
  100. return _noticedTopTitle;
  101. }
  102. - (UILabel *)msgTitleLabel {
  103. if (!_msgTitleLabel) {
  104. _msgTitleLabel = [[UILabel alloc] init];
  105. _msgTitleLabel.textColor = TXHexRGB(0x333333);
  106. _msgTitleLabel.font = [UIFont systemFontOfSize:15.0f weight:UIFontWeightSemibold];
  107. }
  108. return _msgTitleLabel;
  109. }
  110. - (UILabel *)msgContentLabel {
  111. if (!_msgContentLabel) {
  112. _msgContentLabel = [[UILabel alloc] init];
  113. _msgContentLabel.textColor = TXHexRGB(0x333333);
  114. _msgContentLabel.font = [UIFont systemFontOfSize:15.0f weight:UIFontWeightRegular];
  115. _msgContentLabel.numberOfLines = 0;
  116. }
  117. return _msgContentLabel;
  118. }
  119. /*
  120. // Only override drawRect: if you perform custom drawing.
  121. // An empty implementation adversely affects performance during animation.
  122. - (void)drawRect:(CGRect)rect {
  123. // Drawing code
  124. }
  125. */
  126. @end