进房动画 铭牌显示
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#import "XPRoomMessageParser.h"
|
||||
#import <YYText/YYText.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
#import <Masonry/Masonry.h>
|
||||
///Tool
|
||||
#import "ThemeColor+Room.h"
|
||||
#import "XPRoomMessageConstant.h"
|
||||
@@ -23,7 +24,6 @@
|
||||
#import "UserInfoModel.h"
|
||||
#import "MicroStateModel.h"
|
||||
#import "RoomInfoModel.h"
|
||||
#import "XPUserEnterRoomExtModel.h"
|
||||
|
||||
#import "NetImageView.h"
|
||||
|
||||
@@ -87,6 +87,11 @@
|
||||
[attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
if (model.inRoomNameplatePic.length > 0 && model.inRoomNameplateWord.length > 0) {
|
||||
[attribute appendAttributedString:[self createNameplateAttibute:model.inRoomNameplateWord image:model.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:message.text color:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont]];
|
||||
@@ -113,8 +118,14 @@
|
||||
NSString* nick = member.nick.length > 0 ? member.nick : @"";
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
NSDictionary * dic = [(NSDictionary *)messageExt.roomExt.toJSONObject objectForKey:message.from];
|
||||
XPUserEnterRoomExtModel * extModel = [XPUserEnterRoomExtModel modelWithDictionary:dic];;
|
||||
XPMessageRemoteExtModel * extModel = [XPMessageRemoteExtModel modelWithDictionary:dic];
|
||||
if (extModel.inRoomNameplatePic.length > 0 && extModel.inRoomNameplateWord.length > 0) {
|
||||
[attribute appendAttributedString:[self createNameplateAttibute:extModel.inRoomNameplateWord image:extModel.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
[attribute appendAttributedString:[self createTextAttribute:nick color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||||
|
||||
if (extModel.carName.length > 0) {
|
||||
[attribute appendAttributedString:[self createTextAttribute:@" 驾着 " color:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont]];
|
||||
[attribute appendAttributedString:[self createTextAttribute:extModel.carName color:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont]];
|
||||
@@ -401,6 +412,45 @@
|
||||
}
|
||||
|
||||
#pragma mark - private base methods
|
||||
///铭牌
|
||||
- (NSMutableAttributedString *)createNameplateAttibute:(NSString *)tagName image:(NSString *)imageName textFont:(UIFont *)textFont {
|
||||
NetImageConfig *config = [[NetImageConfig alloc]init];
|
||||
///先这样吧
|
||||
config.autoLoad = YES;
|
||||
NetImageView *imageView = [[NetImageView alloc]initWithUrl:imageName config:config];
|
||||
UIImage* image = imageView.image;
|
||||
if (image) {
|
||||
CGFloat scale = image.size.width / image.size.height;
|
||||
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
|
||||
} else {
|
||||
NSURL *imgUrl = [NSURL URLWithString:imageName];
|
||||
UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]];
|
||||
CGFloat scale = myImage.size.width / myImage.size.height;
|
||||
if (scale == 0) {
|
||||
imageView.bounds = CGRectMake(0, 0, 60, 20);
|
||||
}else {
|
||||
imageView.bounds = CGRectMake(0, 0, 20* scale, 20);
|
||||
}
|
||||
}
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
// 铭牌文字
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.font = [UIFont boldSystemFontOfSize:12];
|
||||
label.adjustsFontSizeToFitWidth = YES;
|
||||
label.textColor = UIColor.whiteColor;
|
||||
label.text = tagName;
|
||||
[imageView addSubview:label];
|
||||
[label mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(27);
|
||||
make.right.mas_equalTo(-8);
|
||||
make.centerY.mas_equalTo(0);
|
||||
}];
|
||||
NSMutableAttributedString *string = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.bounds.size alignToFont:[UIFont boldSystemFontOfSize:12] alignment:YYTextVerticalAlignmentCenter];
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/// 生成一个图片的富文本
|
||||
/// @param imageUrl 网络图片的地址
|
||||
- (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl {
|
||||
|
Reference in New Issue
Block a user