// // TXGroupNoticeMessageContentView.m // TUIChat // // Created by 王智 on 2024/8/30. // #import "TXGroupNoticeMessageContentView.h" #import "Masonry.h" #import "UIImageView+WebCache.h" #import "TUIDefine.h" #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] @interface TXGroupNoticeMessageContentView () @property (nonatomic, strong) UIImageView *noticeIcon; @property (nonatomic, strong) UILabel *noticedTopTitle; @property (nonatomic, strong) UILabel *msgTitleLabel; @property (nonatomic, strong) UILabel *msgContentLabel; @end @implementation TXGroupNoticeMessageContentView + (instancetype)shareIntance { return [[TXGroupNoticeMessageContentView alloc] init]; } - (instancetype)init { self = [super init]; if (self) { [self configUI]; } return self; } - (void)configUI { self.backgroundColor = [UIColor whiteColor]; self.layer.cornerRadius = 10.0f; [self addSubview:self.noticeIcon]; [self.noticeIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(12); make.top.mas_equalTo(self.mas_top).offset(13); make.width.mas_equalTo(18); make.height.mas_equalTo(18); }]; [self addSubview:self.noticedTopTitle]; [self.noticedTopTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.noticeIcon.mas_right).offset(6); make.height.mas_equalTo(21); make.top.mas_equalTo(self.mas_top).offset(11); }]; [self addSubview:self.msgTitleLabel]; [self.msgTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(12); make.right.mas_equalTo(self.mas_right).offset(-12); make.top.mas_equalTo(self.noticedTopTitle.mas_bottom).offset(11); make.height.mas_equalTo(21); }]; [self addSubview:self.msgContentLabel]; [self.msgContentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(12); make.right.mas_equalTo(self.mas_right).offset(-12); make.top.mas_equalTo(self.msgTitleLabel.mas_bottom); }]; } - (void)configCellWithMsgTitle:(NSString *)title content:(NSString *)content { self.msgTitleLabel.text = [self returnNoNullStringWithString:title]; if (![self isEmptyString:content]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.maximumLineHeight = 21; paragraphStyle.minimumLineHeight = 21; UIFont *font = [UIFont systemFontOfSize:16.0f]; CGFloat baseLineOffset = (21 - font.lineHeight) / 4; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font,NSForegroundColorAttributeName:TXHexRGB(0x333333),NSBaselineOffsetAttributeName:@(baseLineOffset)}]; self.msgContentLabel.attributedText = attr; } else { self.msgContentLabel.text = @""; } } - (NSString *)returnNoNullStringWithString:(NSString *)string { if (string == nil || string.length == 0) { return @""; } return string; } - (NSString *)getUrlEndcodeString:(NSString *)string { NSString *url = [string stringByRemovingPercentEncoding]; return [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];; } - (BOOL)isEmptyString:(NSString *)str { if (str == nil || str.length == 0) { return YES; } return NO; } #pragma mark ------ notice content view - (UIImageView *)noticeIcon { if (!_noticeIcon) { _noticeIcon = [[UIImageView alloc] init]; [_noticeIcon setImage:TUIChatBundleThemeImage(@"chat_custom_order_message_img", @"TXGroupNoticeMessageIcon")]; } return _noticeIcon; } - (UILabel *)noticedTopTitle { if (!_noticedTopTitle) { _noticedTopTitle = [[UILabel alloc] init]; _noticedTopTitle.textColor = TXHexRGB(0x19B396); _noticedTopTitle.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightRegular]; _noticedTopTitle.text = @"群公告"; } return _noticedTopTitle; } - (UILabel *)msgTitleLabel { if (!_msgTitleLabel) { _msgTitleLabel = [[UILabel alloc] init]; _msgTitleLabel.textColor = TXHexRGB(0x333333); _msgTitleLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightSemibold]; } return _msgTitleLabel; } - (UILabel *)msgContentLabel { if (!_msgContentLabel) { _msgContentLabel = [[UILabel alloc] init]; _msgContentLabel.textColor = TXHexRGB(0x333333); _msgContentLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightRegular]; _msgContentLabel.numberOfLines = 0; } return _msgContentLabel; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end