12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // TXLiveShareMessage.m
- // TUIChat
- //
- // Created by 王智 on 2023/8/10.
- //
- #import "TXLiveShareMessage.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]
- @implementation TXLiveShareMessage
- + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message {
- NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil];
- TXLiveShareMessage *cellData = [[TXLiveShareMessage alloc] initWithDirection:message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming];
- cellData.innerMessage = message;
- cellData.msgID = message.msgID;
-
- cellData.roomUID = param[@"roomUID"];
- cellData.teacherAvatar = param[@"teacherAvatar"];
- cellData.teacherName = param[@"teacherName"];
- cellData.liveDescMessage = param[@"liveDescMessage"];
-
- return cellData;
- }
- + (NSString *)getDisplayString:(V2TIMMessage *)message {
- return @"[直播分享]";
- }
- - (CGSize)contentSize {
- CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width);
- if (![self isEmptyString:self.liveDescMessage]) {
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
-
- CGFloat height = [self.liveDescMessage boundingRectWithSize:CGSizeMake(260, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:TXHexRGB(0x666666)} context:nil].size.height + 6;
- CGFloat contentHeight = height + 123 + 20;
- return CGSizeMake(width, contentHeight);
- }
- else {
- return CGSizeMake(width, 123 + 20);
- }
- }
- - (BOOL)isEmptyString:(NSString *)str {
- if (str == nil || str.length == 0) {
- return YES;
- }
- return NO;
- }
- @end
|