TXGroupNoticeMessageContentView.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  63. paragraphStyle.maximumLineHeight = 21;
  64. paragraphStyle.minimumLineHeight = 21;
  65. UIFont *font = [UIFont systemFontOfSize:16.0f];
  66. CGFloat baseLineOffset = (21 - font.lineHeight) / 4;
  67. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font,NSForegroundColorAttributeName:TXHexRGB(0x333333),NSBaselineOffsetAttributeName:@(baseLineOffset)}];
  68. self.msgContentLabel.attributedText = attr;
  69. }
  70. else {
  71. self.msgContentLabel.text = @"";
  72. }
  73. }
  74. - (NSString *)returnNoNullStringWithString:(NSString *)string {
  75. if (string == nil || string.length == 0) {
  76. return @"";
  77. }
  78. return string;
  79. }
  80. - (NSString *)getUrlEndcodeString:(NSString *)string {
  81. NSString *url = [string stringByRemovingPercentEncoding];
  82. return [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];;
  83. }
  84. - (BOOL)isEmptyString:(NSString *)str {
  85. if (str == nil || str.length == 0) {
  86. return YES;
  87. }
  88. return NO;
  89. }
  90. #pragma mark ------ notice content view
  91. - (UIImageView *)noticeIcon {
  92. if (!_noticeIcon) {
  93. _noticeIcon = [[UIImageView alloc] init];
  94. [_noticeIcon setImage:TUIChatBundleThemeImage(@"chat_custom_order_message_img", @"TXGroupNoticeMessageIcon")];
  95. }
  96. return _noticeIcon;
  97. }
  98. - (UILabel *)noticedTopTitle {
  99. if (!_noticedTopTitle) {
  100. _noticedTopTitle = [[UILabel alloc] init];
  101. _noticedTopTitle.textColor = TXHexRGB(0x19B396);
  102. _noticedTopTitle.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightRegular];
  103. _noticedTopTitle.text = @"群公告";
  104. }
  105. return _noticedTopTitle;
  106. }
  107. - (UILabel *)msgTitleLabel {
  108. if (!_msgTitleLabel) {
  109. _msgTitleLabel = [[UILabel alloc] init];
  110. _msgTitleLabel.textColor = TXHexRGB(0x333333);
  111. _msgTitleLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightSemibold];
  112. }
  113. return _msgTitleLabel;
  114. }
  115. - (UILabel *)msgContentLabel {
  116. if (!_msgContentLabel) {
  117. _msgContentLabel = [[UILabel alloc] init];
  118. _msgContentLabel.textColor = TXHexRGB(0x333333);
  119. _msgContentLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightRegular];
  120. _msgContentLabel.numberOfLines = 0;
  121. }
  122. return _msgContentLabel;
  123. }
  124. /*
  125. // Only override drawRect: if you perform custom drawing.
  126. // An empty implementation adversely affects performance during animation.
  127. - (void)drawRect:(CGRect)rect {
  128. // Drawing code
  129. }
  130. */
  131. @end