Files
peko-ios/YuMi/Modules/YMMessage/View/Session/Content/SesssionModel/MSSessionPublicChatHalImageModel.m
liyuhua d22d0aa9fe 1.UI修改
2.修复bug
2024-05-17 11:27:36 +08:00

92 lines
4.4 KiB
Objective-C

//
// MSSessionPublicChatHalImageModel.m
// YuMi
//
// Created by duoban on 2024/5/10.
//
#import "MSSessionPublicChatHalImageModel.h"
#define MESSAGE_IMAGE_MAX_SIZE (CONTENT_WIDTH_MAX)
#define MESSAGE_IMAGE_Min_SIZE (CONTENT_WIDTH_MAX -100)
@implementation MSSessionPublicChatHalImageModel
- (instancetype)initWithMessage:(NIMMessage *)message {
if (self = [super initWithMessage:message]) {
self.messageType = SessionMessageType_Image;
XPMessageRemoteExtModel *extModel = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
self.extModel = extModel;
self.isSelf = [[NIMSDK sharedSDK].loginManager.currentAccount isEqualToString:message.from];
NIMImageObject * imageObject = (NIMImageObject*)message.messageObject;
CGFloat attachmentImageMinWidth = (MESSAGE_IMAGE_Min_SIZE);
CGFloat attachmentImageMinHeight = (MESSAGE_IMAGE_Min_SIZE);
CGFloat attachmemtImageMaxWidth = (MESSAGE_IMAGE_MAX_SIZE);
CGFloat attachmentImageMaxHeight = (MESSAGE_IMAGE_MAX_SIZE);
CGSize imageSize;
if (!CGSizeEqualToSize(imageObject.size, CGSizeZero)) {
imageSize = imageObject.size;
}else {
UIImage *image = [UIImage imageWithContentsOfFile:imageObject.thumbPath];
imageSize = image ? image.size : CGSizeZero;
}
CGSize contentSize = [UIImage sizeWithImageOriginSize:imageSize
minSize:CGSizeMake(attachmentImageMinWidth, attachmentImageMinHeight)
maxSize:CGSizeMake(attachmemtImageMaxWidth, attachmentImageMaxHeight)];
self.contentSize = contentSize;
self.height = contentSize.height + kGetScaleWidth(40) + (self.isSelf ? 0 : kGetScaleWidth(65));
UIImage *image = [UIImage imageWithContentsOfFile:imageObject.thumbPath];
if (image) {
self.image = image;
}else {
self.imageUrl = imageObject.url;
}
self.url = imageObject.url;
self.isHiddenAvatar = YES;
}
return self;
}
- (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size {
NetImageConfig *config = [[NetImageConfig alloc]init];
///先这样吧
config.autoLoad = YES;
NetImageView *imageView = [[NetImageView alloc]initWithUrl:imageUrl config:config];
imageView.bounds = CGRectMake(0, 0, size.width, size.height);
imageView.layer.masksToBounds = YES;
imageView.contentMode = UIViewContentModeScaleAspectFit;
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
return attrString;
}
/// 占位的富文本
/// @param width 需要的间隙
- (NSMutableAttributedString *)createSapceAttribute:(CGFloat)width {
UIView *spaceView = [[UIView alloc]init];
spaceView.backgroundColor = [UIColor clearColor];
spaceView.bounds = CGRectMake(0, 0, width, 10);
NSMutableAttributedString * attribute = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(spaceView.frame.size.width, spaceView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
return attribute;
}
/// 生成一个富文本
/// @param text 富文本的文字
/// @param color 文字的颜色
/// @param font 文字的大小
- (NSMutableAttributedString *)createTextAttribute:(NSString *)text color:(UIColor *)color font:(UIFont *)font {
if (text == nil || text.length <= 0) {
text = @"";
}
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil];
attribute.yy_font = font;
attribute.yy_color = color;
attribute.yy_paragraphStyle = [self paragraphStyle];
return attribute;
}
/// 设置文本的样式 间隙 缩进 ...
- (NSMutableParagraphStyle *)paragraphStyle {
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineSpacing = 4.0f;//行间距
// 强制排版(从左到右)
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
return paraStyle;
}
@end