2021-11-04 16:27:39 +08:00
//
// XPRoomMessageParser . m
// xplan - ios
//
// Created by 冯 硕 on 2021 / 10 / 26.
//
# import "XPRoomMessageParser.h"
# import < YYText / YYText . h >
# import < NIMSDK / NIMSDK . h >
2021-12-17 15:18:34 +08:00
# import < Masonry / Masonry . h >
2021-11-04 16:27:39 +08:00
// / Tool
# import "ThemeColor+Room.h"
# import "XPRoomMessageConstant.h"
# import "AccountInfoStorage.h"
# import "XPMacro.h"
2021-11-17 19:29:14 +08:00
# import "XPGiftStorage.h"
2021-11-04 16:27:39 +08:00
// / Model
# import "XPMessageRemoteExtModel.h"
2021-11-17 19:29:14 +08:00
# import "AttachMentModel.h"
# import "GiftReceiveInfoModel.h"
2021-11-26 17:31:12 +08:00
# import "XPKickUserModel.h"
2021-11-26 21:47:00 +08:00
# import "MicroQueueModel.h"
# import "UserInfoModel.h"
# import "MicroStateModel.h"
2021-12-13 19:44:15 +08:00
# import "RoomInfoModel.h"
2022-01-05 21:48:21 +08:00
# import "DatingInfoModel.h"
2021-11-04 16:27:39 +08:00
# import "NetImageView.h"
2021-11-26 21:47:00 +08:00
# import "XPUserCardViewController.h"
2021-11-04 16:27:39 +08:00
@ implementation XPRoomMessageParser
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) parseMessageAttribute : ( NIMMessage * ) message {
2021-11-04 16:27:39 +08:00
NIMMessageType messageType = message . messageType ;
switch ( messageType ) {
case NIMMessageTypeText :
return [ self makeChatAttribute : message ] ;
case NIMMessageTypeTip :
return [ self makeTipsAttribute : message ] ;
case NIMMessageTypeNotification :
return [ self makeNotificationAttribute : message ] ;
2021-11-17 19:29:14 +08:00
case NIMMessageTypeCustom :
return [ self makeCustomAttribute : message ] ;
2021-11-04 16:27:39 +08:00
default :
return nil ;
}
}
// / 用 户 公 屏 聊 天
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) makeCustomAttribute : ( NIMMessage * ) message {
2021-11-17 19:29:14 +08:00
NIMCustomObject * obj = ( NIMCustomObject * ) message . messageObject ;
AttachmentModel * attachment = ( AttachmentModel * ) obj . attachment ;
XPMessageRemoteExtModel * model = [ XPMessageRemoteExtModel modelWithJSON : message . remoteExt [ message . from ] ] ;
int first = attachment . first ;
if ( first = = CustomMessageType_Gift ) { // / 单 人 送
return [ self createSendGiftAttribute : attachment sendInfo : model ] ;
2021-12-06 17:00:15 +08:00
} else if ( first = = CustomMessageType_AllMicroSend ) { // / 全 麦 送 多 人 送
2021-11-17 19:29:14 +08:00
return [ self createBatchMicroSendGiftAttribute : attachment sendInfo : model ] ;
2021-11-24 14:58:53 +08:00
} else if ( first = = CustomMessageType_Room _Tip ) { // / 分 享 / 收 藏 房 间
2021-11-26 21:47:00 +08:00
return [ self createShareOrAttentionRoomAttribute : attachment sendInfo : model uid : message . from ] ;
} else if ( first = = CustomMessageType_Kick _User || first = = CustomMessageType_Queue ) {
2021-11-26 17:31:12 +08:00
XPKickUserModel * kickModel = [ XPKickUserModel modelWithJSON : attachment . data ] ;
return [ self createKickUserAttribute : attachment info : kickModel ] ;
2021-12-10 21:20:34 +08:00
} else if ( first = = CustomMessageType_Candy _Tree ) { // 糖 果 树
return [ self createCandyTreeHighLevelAttribute : attachment ] ;
2021-12-20 21:17:12 +08:00
} else if ( first = = CustomMessageType_Arrange _Mic ) {
return [ self createArrangeMicAttribute : attachment ] ;
2021-12-25 16:57:50 +08:00
} else if ( first = = CustomMessageType_Update _RoomInfo ) {
return [ self createRoomInfoUpdateAttribute : attachment ] ;
2021-12-27 16:40:14 +08:00
} else if ( first = = CustomMessageType_Collection _Room ) {
return [ self createCollectRoomAttribute : attachment ] ;
2022-01-05 21:48:21 +08:00
} else if ( first = = CustomMessageType_RoomPlay _Dating ) {
return [ self createRoomDatingAttribute : attachment ] ;
2021-11-17 19:29:14 +08:00
}
return nil ;
}
2021-11-04 16:27:39 +08:00
// / @ param message 消 息 的 实 体
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) makeChatAttribute : ( NIMMessage * ) message {
2021-11-04 16:27:39 +08:00
NSString * uid = [ AccountInfoStorage instance ] . getUid ;
XPMessageRemoteExtModel * model = [ XPMessageRemoteExtModel modelWithJSON : message . remoteExt [ message . from ] ] ;
NSString * nick = [ NSString stringWithFormat : @ "%@:" , ( ( NIMMessageChatroomExtension * ) message . messageExt ) . roomNickname ] ;
if ( [ message . from isEqualToString : uid ] ) {
nick = @ "我:" ;
}
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2021-11-24 14:58:53 +08:00
// / 官 方 新 用 户
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : model . defUser newUser : model . newUser ] ] ;
2021-11-04 16:27:39 +08:00
if ( model . experUrl ) {
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createUrlImageAttribute : model . experUrl ] ] ;
2021-11-04 16:27:39 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2021-12-17 15:18:34 +08:00
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 ] ] ;
}
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-04 16:27:39 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : message . text color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-26 21:47:00 +08:00
[ self attributeAddHihtLight : attribute uid : message . from . integerValue ] ;
2021-11-04 16:27:39 +08:00
return attribute ;
}
// / 房 间 tips 消 息
// / @ param message 消 息 的 实 体
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) makeTipsAttribute : ( NIMMessage * ) message {
2022-01-05 21:48:21 +08:00
return [ self createTextAttribute : message . text color : UIColorFromRGB ( 0 xFE5D7F ) font : kRoomMessageDefalutFont ] ;
2021-11-04 16:27:39 +08:00
}
// / 房 间 通 知 类 消 息
// / @ param message 消 息 的 实 体
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) makeNotificationAttribute : ( NIMMessage * ) message {
2021-11-04 16:27:39 +08:00
NIMNotificationObject * notiMsg = ( NIMNotificationObject * ) message . messageObject ;
NIMChatroomNotificationContent * content = ( NIMChatroomNotificationContent * ) notiMsg . content ;
NIMChatroomNotificationMember * member = content . targets [ 0 ] ;
2021-12-16 20:22:01 +08:00
NIMMessageChatroomExtension * messageExt = ( NIMMessageChatroomExtension * ) message . messageExt ;
2021-11-04 16:27:39 +08:00
switch ( content . eventType ) {
case NIMChatroomEventTypeEnter : // / 进 入 房 间
{
NSString * nick = member . nick . length > 0 ? member . nick : @ "" ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2021-12-16 20:22:01 +08:00
NSDictionary * dic = [ ( NSDictionary * ) messageExt . roomExt . toJSONObject objectForKey : message . from ] ;
2021-12-17 15:18:34 +08:00
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 ] ] ;
}
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-17 15:18:34 +08:00
2021-12-16 20:22:01 +08:00
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 ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "进入了房间" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-26 21:47:00 +08:00
[ self attributeAddHihtLight : attribute uid : message . from . integerValue ] ;
2021-11-04 16:27:39 +08:00
return attribute ;
}
2021-12-25 16:57:50 +08:00
break ;
2022-01-05 21:48:21 +08:00
case NIMChatroomEventTypeInfoUpdated : {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
if ( self . hostDelegate . getRoomInfo . isOpenRoomDating ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "相亲玩法已开启,请点击主持人麦位选择主持人" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
return attribute ;
}
}
break ;
2021-11-04 16:27:39 +08:00
default :
return nil ;
}
2022-01-05 21:48:21 +08:00
return nil ;
2021-11-04 16:27:39 +08:00
}
2021-12-27 16:40:14 +08:00
# pragma mark - 收 藏 房 间
- ( NSAttributedString * ) createCollectRoomAttribute : ( AttachmentModel * ) attachment {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
NSDictionary * data = attachment . data [ @ "data" ] ;
NSString * nick = [ NSString stringWithFormat : @ "%@" , data [ @ "nick" ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * tipString = @ "" ;
if ( attachment . second = = Custom_Message _Sub _Collect _Room _Tips ) {
tipString = @ "收藏了房间" ;
}
[ attribute appendAttributedString : [ self createTextAttribute : tipString color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
return attribute ;
}
2021-11-17 19:29:14 +08:00
# pragma mark - 房 间 信 息 更 新
2021-12-25 16:57:50 +08:00
- ( NSAttributedString * ) createRoomInfoUpdateAttribute : ( AttachmentModel * ) attachment {
if ( attachment . second = = Custom_Message _Sub _Update _RoomInfo _MessageState ) {
NSDictionary * dic = attachment . data [ @ "roomInfo" ] ;
if ( dic . allKeys . count <= 0 ) {
dic = attachment . data ;
}
RoomInfoModel * roomInfo = [ RoomInfoModel modelWithDictionary : dic ] ;
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "消息:" color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
if ( roomInfo . isCloseScreen ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "管理员已关闭聊天公屏" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
} else {
[ attribute appendAttributedString : [ self createTextAttribute : @ "管理员已开启聊天公屏" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
return attribute ;
2021-12-27 17:10:36 +08:00
} else if ( attachment . second = = Custom_Message _Sub _Update _RoomInfo _AnimateEffect ) {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "消息:" color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "管理员已关闭房间内礼物特效,点击底部" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createImageAttribute : [ UIImage imageNamed : @ "room_menu_more" ] ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "图标即可开启" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
return attribute ;
2021-12-25 16:57:50 +08:00
}
2021-11-04 16:27:39 +08:00
return nil ;
}
2022-01-05 21:48:21 +08:00
# pragma mark - 相 亲
- ( NSAttributedString * ) createRoomDatingAttribute : ( AttachmentModel * ) attachment {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
if ( attachment . second = = Custom_Message _Sub _Room _Play _Dating _Pick _Heart ) {
DatingInfoModel * datingModel = [ DatingInfoModel modelWithDictionary : attachment . data ] ;
NSString * targetGender = datingModel . targetGender = = GenderType_Male ? @ "男" : @ "女" ;
NSString * pickString = [ NSString stringWithFormat : @ "%d号%@嘉宾:" , ( datingModel . targetPosition + 1 ) , targetGender ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "本轮你选择了" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : pickString color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * targetNick = datingModel . targetNickname ? datingModel . targetNickname : @ "" ;
[ attribute appendAttributedString : [ self createNickAtrribute : targetNick uid : datingModel . targetUid ] ] ;
NSString * heartContent = @ "作为你的心动对象" ;
[ attribute appendAttributedString : [ self createTextAttribute : heartContent color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
} else if ( attachment . second = = Custom_Message _Sub _Room _Play _Dating _Result _Mutual ) { // / 互 选
DatingInfoModel * datingModel = [ DatingInfoModel modelWithDictionary : attachment . data ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "恭喜" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * nick = datingModel . nickname ? datingModel . nickname : @ "" ;
[ attribute appendAttributedString : [ self createNickAtrribute : nick uid : datingModel . uid ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "和" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * targetNick = datingModel . targetNickname ? datingModel . targetNickname : @ "" ;
[ attribute appendAttributedString : [ self createNickAtrribute : targetNick uid : datingModel . targetUid ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "牵手成功,让我们见证他们幸福的开端" color : UIColorFromRGB ( 0 xF84C95 ) font : kRoomMessageDefalutFont ] ] ;
} else if ( attachment . second = = Custom_Message _Sub _Room _Play _Dating _Result _Not _Mutual ) { // / 不 是 互 选
DatingInfoModel * datingModel = [ DatingInfoModel modelWithDictionary : attachment . data ] ;
NSString * nick = datingModel . nickname ? datingModel . nickname : @ "" ;
[ attribute appendAttributedString : [ self createNickAtrribute : nick uid : datingModel . uid ] ] ;
if ( datingModel . hasSelectUser ) { // 选 择 的 有 人
[ attribute appendAttributedString : [ self createTextAttribute : @ "的心动对象是" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * targetNick = datingModel . targetNickname ? datingModel . targetNickname : @ "" ;
[ attribute appendAttributedString : [ self createNickAtrribute : targetNick uid : datingModel . targetUid ] ] ;
} else { // / 没 有 选 择 人
[ attribute appendAttributedString : [ self createTextAttribute : @ "未选择心动对象" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
}
return attribute ;
}
2021-12-20 21:17:12 +08:00
# pragma mark - 排 麦
- ( NSAttributedString * ) createArrangeMicAttribute : ( AttachmentModel * ) attachment {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "管理员" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
if ( attachment . second = = Custom_Message _Sub _Arrange _Mic _Mode _Open ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "开启了" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "排麦模式" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
} else if ( attachment . second = = Custom_Message _Sub _Arrange _Mic _Mode _Close ) {
[ attribute appendAttributedString : [ self createTextAttribute : @ "关闭了" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "排麦模式" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
} else if ( attachment . second = = Custom_Message _Sub _Arrange _Mic _Free _Mic _Open ) {
NSDictionary * dic = attachment . data ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "设置" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%d麦" , ( ( NSNumber * ) dic [ @ "micPos" ] ) . intValue + 1 ] color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "为自由麦" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
} else if ( attachment . second = = Custom_Message _Sub _Arrange _Mic _Free _Mic _Close ) {
NSDictionary * dic = attachment . data ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "关闭了" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%d麦" , ( ( NSNumber * ) dic [ @ "micPos" ] ) . intValue + 1 ] color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : @ "自由麦" color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
}
return attribute ;
}
2021-12-10 21:20:34 +08:00
# pragma mark - 糖 果 树 公 屏 消 息
- ( NSAttributedString * ) createCandyTreeHighLevelAttribute : ( AttachmentModel * ) attachment {
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
// action
[ attribute appendAttributedString : [ self createTextAttribute : @ "厉害了 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
NSInteger uid = 0 ;
if ( [ attachment . data [ @ "uid" ] isKindOfClass : [ NSNumber class ] ] ) {
uid = ( ( NSNumber * ) attachment . data [ @ "uid" ] ) . integerValue ;
} else if ( [ attachment . data [ @ "uid" ] isKindOfClass : [ NSString class ] ] ) {
uid = ( ( NSString * ) attachment . data [ @ "uid" ] ) . integerValue ;
}
2021-12-23 15:21:16 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : attachment . data [ @ "nick" ] color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-10 21:20:34 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "摘下糖果获得" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : attachment . data [ @ "prizeName" ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-11 17:02:42 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " x %@" , attachment . data [ @ "prizeNum" ] ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-12-23 15:21:16 +08:00
[ self attributeAddHihtLight : attribute uid : uid ] ;
2021-12-10 21:20:34 +08:00
return attribute ;
}
2021-11-26 17:31:12 +08:00
# pragma mark - 踢 出 房 间 / 拉 黑 / 下 麦
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) createKickUserAttribute : ( AttachmentModel * ) attachment info : ( XPKickUserModel * ) info {
2021-11-26 17:31:12 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . targetNick uid : info . targetUid ] ] ;
2021-11-26 17:31:12 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "被" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . handleNick uid : info . handleUid ] ] ;
2021-11-26 17:31:12 +08:00
NSString * content = @ "" ;
if ( attachment . second = = Custom_Message _Sub _Kick _BeKicked ) {
content = @ "请出房间" ;
} else if ( attachment . second = = Custom_Message _Sub _Kick _BlackList ) {
content = @ "关进小黑屋" ;
2021-11-26 21:47:00 +08:00
} else if ( attachment . second = = Custom_Message _Sub _Queue _Kick ) {
content = @ "请下麦" ;
2021-11-26 17:31:12 +08:00
}
[ attribute appendAttributedString : [ self createTextAttribute : content color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
return attribute ;
}
2021-12-27 16:40:14 +08:00
# pragma mark - 分 享 房 间
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) createShareOrAttentionRoomAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo uid : ( NSString * ) uid {
2021-11-24 14:58:53 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
NSDictionary * data = attachment . data [ @ "data" ] ;
NSString * nick = [ NSString stringWithFormat : @ "%@" , data [ @ "nick" ] ] ;
[ attribute appendAttributedString : [ self createTextAttribute : nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
NSString * tipString = @ "" ;
if ( attachment . second = = Custom_Message _Sub _Room _Tip _ShareRoom ) {
tipString = @ "分享了房间" ;
} else if ( attachment . second = = Custom_Message _Sub _Room _Tip _Attention _Owner ) {
tipString = @ "关注了房主" ;
}
[ attribute appendAttributedString : [ self createTextAttribute : tipString color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-26 21:47:00 +08:00
[ self attributeAddHihtLight : attribute uid : uid . integerValue ] ;
2021-11-24 14:58:53 +08:00
return attribute ;
}
2021-11-17 19:29:14 +08:00
# pragma mark - 送 礼 物 的 公 屏
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) createBatchMicroSendGiftAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo {
2021-11-17 19:29:14 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
GiftReceiveInfoModel * info = [ GiftReceiveInfoModel modelWithJSON : attachment . data ] ;
GiftInfoModel * giftInfo = info . gift = = nil ? info . giftInfo : info . gift ;
if ( giftInfo = = nil ) {
giftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : info . giftId ] ;
}
2021-11-24 14:58:53 +08:00
// / 官 方 新 用 户
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : sendInfo . defUser newUser : sendInfo . newUser ] ] ;
2021-11-17 19:29:14 +08:00
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . nick uid : info . uid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
if ( attachment . second = = Custom_Message _Sub _AllBatchSend || attachment . second = = Custom_Message _Sub _AllMicroSend ) { // / 普 通 礼 物
if ( attachment . second = = Custom_Message _Sub _AllBatchSend ) {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
for ( int i = 0 ; i < info . targetUsers . count ; i + + ) {
GiftReceiveUserInfoModel * targetInfo = [ info . targetUsers objectAtIndex : i ] ;
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : targetInfo . nick uid : targetInfo . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
if ( i < ( info . targetUsers . count -1 ) ) {
// nick
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
}
} else {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 全麦打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
// img
if ( giftInfo . giftUrl ) {
[ attribute appendAttributedString : [ self createUrlImageAttribute : giftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , info . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
} else if ( attachment . second = = Custom_Message _Sub _AllMicroLuckySend || attachment . second = = Custom_Message _Sub _AllBatchMicroLuckySend ) { // / 福 袋 礼 物
// action
NSString * sendTitle = @ " 送出 " ;
if ( attachment . second = = Custom_Message _Sub _AllMicroLuckySend ) {
sendTitle = @ " 全麦送出 " ;
}
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : sendTitle color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : info . giftName color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 给 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
if ( info . luckyGiftList ) {
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . luckyGiftList . user . nick uid : info . luckyGiftList . user . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 爆出了 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
[ info . luckyGiftList . giftList enumerateObjectsUsingBlock : ^ ( GiftListsInfo * _Nonnull giftListInfo , NSUInteger idx , BOOL * _Nonnull stop ) {
2021-12-23 15:10:11 +08:00
GiftInfoModel * luckGiftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : [ NSString stringWithFormat : @ "%ld" , giftListInfo . giftId ] ] ;
2021-11-17 19:29:14 +08:00
// 价 值
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "价值" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 礼 物 价 格
2021-12-23 15:10:11 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%ld" , ( NSInteger ) luckGiftInfo . goldPrice ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 的 礼 物
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "钻石的礼物" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : luckGiftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , giftListInfo . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
if ( info . luckyGiftList . giftList . count -1 ! = idx ) {
// ,
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
} ] ;
}
}
return attribute ;
}
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) createSendGiftAttribute : ( AttachmentModel * ) attachment sendInfo : ( XPMessageRemoteExtModel * ) sendInfo {
2021-11-17 19:29:14 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
GiftReceiveInfoModel * info = [ GiftReceiveInfoModel modelWithJSON : attachment . data ] ;
GiftInfoModel * giftInfo = info . gift = = nil ? info . giftInfo : info . gift ;
if ( giftInfo = = nil ) {
giftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : info . giftId ] ;
}
2021-11-24 14:58:53 +08:00
// / 官 方 新 用 户
[ attribute appendAttributedString : [ self createOfficalAndNewuserAttribute : sendInfo . defUser newUser : sendInfo . newUser ] ] ;
2021-11-17 19:29:14 +08:00
// nick
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . nick uid : info . uid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;;
if ( attachment . second = = Custom_Message _Sub _Gift _LuckySend ) {
// action
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "送出" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 福 袋 名 称
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : info . giftName color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "给" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . luckyGiftList . user . nick uid : info . luckyGiftList . user . uid ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// lucky
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "爆出了" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ info . luckyGiftList . giftList enumerateObjectsUsingBlock : ^ ( GiftListsInfo * _Nonnull giftListInfo , NSUInteger idx , BOOL * _Nonnull stop ) {
GiftInfoModel * luckyGiftInfo = [ [ XPGiftStorage shareStorage ] findGiftInfo : [ NSString stringWithFormat : @ "%ld" , giftListInfo . giftId ] ] ;
// 价 值
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "价值" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// 礼 物 价 格
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ "%ld" , ( NSInteger ) giftInfo . goldPrice ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// 的 礼 物
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "钻石的礼物" color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : luckyGiftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , giftListInfo . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
if ( info . luckyGiftList . giftList . count -1 ! = idx ) {
// ,
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ "," color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
} ] ;
} else {
// 打 赏
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : @ " 打赏 " color : [ ThemeColor messageDefaultTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// target
2021-11-26 21:47:00 +08:00
[ attribute appendAttributedString : [ self createNickAtrribute : info . targetNick uid : info . targetUid . integerValue ] ] ;
2021-11-17 19:29:14 +08:00
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// img
[ attribute appendAttributedString : [ self createUrlImageAttribute : giftInfo . giftUrl ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
// x N
2021-11-24 14:58:53 +08:00
[ attribute appendAttributedString : [ self createTextAttribute : [ NSString stringWithFormat : @ " X%ld" , info . giftNum ] color : [ ThemeColor messageTextColor ] font : kRoomMessageDefalutFont ] ] ;
2021-11-17 19:29:14 +08:00
}
return attribute ;
}
2021-11-24 14:58:53 +08:00
# pragma mark - Commond Mehotd
2021-11-26 21:47:00 +08:00
- ( NSAttributedString * ) createOfficalAndNewuserAttribute : ( UserLevelType ) levelType newUser : ( BOOL ) newUser {
2021-11-24 14:58:53 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] init ] ;
// offical
if ( levelType = = UserLevelType_Offical ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_offical" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
if ( newUser ) {
[ attribute appendAttributedString : [ self createLocalImageAttribute : @ "common_new_user" ] ] ;
[ attribute appendAttributedString : [ self createSapceAttribute : 2 ] ] ;
}
return attribute ;
}
2021-11-17 19:29:14 +08:00
2021-11-26 21:47:00 +08:00
// / 名 字 点 击 的
- ( NSMutableAttributedString * ) createNickAtrribute : ( NSString * ) nick uid : ( NSInteger ) uid {
NSMutableAttributedString * attribute = [ self createTextAttribute : nick color : [ ThemeColor messageNickColor ] font : kRoomMessageDefalutFont ] ;
[ self attributeAddHihtLight : attribute uid : uid ] ;
return attribute ;
}
- ( void ) attributeAddHihtLight : ( NSMutableAttributedString * ) attribute uid : ( NSInteger ) uid {
@ kWeakify ( self ) ;
[ attribute yy_setTextHighlightRange : NSMakeRange ( 0 , attribute . length ) color : nil backgroundColor : nil tapAction : ^ ( UIView * _Nonnull containerView , NSAttributedString * _Nonnull text , NSRange range , CGRect rect ) {
@ kStrongify ( self ) ;
if ( uid <= 0 ) { return ; }
[ self showUserCard : uid ] ;
} ] ;
}
- ( void ) showUserCard : ( NSInteger ) uid {
2021-12-13 19:44:15 +08:00
RoomInfoModel * roomInfo = self . hostDelegate . getRoomInfo ;
2021-11-26 21:47:00 +08:00
NSString * targetUid = [ NSString stringWithFormat : @ "%ld" , uid ] ;
XPUserCardInfoModel * model = [ [ XPUserCardInfoModel alloc ] init ] ;
[ [ self . hostDelegate . getMicroQueue allValues ] enumerateObjectsUsingBlock : ^ ( MicroQueueModel * _Nonnull obj , NSUInteger idx , BOOL * _Nonnull stop ) {
if ( uid = = obj . userInfo . uid ) {
model . position = [ NSString stringWithFormat : @ "%d" , obj . microState . position ] ;
model . posState = ( UserCardMicroPosStateType ) obj . microState . posState ;
model . micState = ( UserCardMicroMicStateType ) obj . microState . micState ;
* stop = YES ;
}
} ] ;
model . uid = targetUid ;
2021-12-13 19:44:15 +08:00
model . roomId = [ NSString stringWithFormat : @ "%ld" , roomInfo . roomId ] ;
model . leaveMode = roomInfo . leaveMode ;
model . showGiftValue = roomInfo . showGiftValue ;
model . avatar = roomInfo . avatar ;
model . roomUid = [ NSString stringWithFormat : @ "%ld" , roomInfo . uid ] ;
model . nick = self . hostDelegate . getUserInfo . nick ;
model . delegate = self . hostDelegate ;
XPUserCardViewController * userCardVC = [ [ XPUserCardViewController alloc ] initWithUser : model ] ;
2021-11-26 21:47:00 +08:00
[ self . hostDelegate . getCurrentNav presentViewController : userCardVC animated : YES completion : nil ] ;
}
2021-11-17 19:29:14 +08:00
# pragma mark - private base methods
2021-12-17 15:18:34 +08:00
// / 铭 牌
- ( 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 ;
}
2021-11-04 16:27:39 +08:00
// / 生 成 一 个 图 片 的 富 文 本
// / @ param imageUrl 网 络 图 片 的 地 址
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createUrlImageAttribute : ( NSString * ) imageUrl {
2021-11-25 17:35:31 +08:00
NetImageConfig * config = [ [ NetImageConfig alloc ] init ] ;
2021-12-02 01:05:49 +08:00
// / 先 这 样 吧
config . autoLoad = YES ;
2021-11-25 17:35:31 +08:00
NetImageView * imageView = [ [ NetImageView alloc ] initWithUrl : imageUrl config : config ] ;
2021-11-17 19:29:14 +08:00
UIImage * image = imageView . image ;
if ( image ) {
CGFloat scale = image . size . width / image . size . height ;
imageView . bounds = CGRectMake ( 0 , 0 , 20 * scale , 20 ) ;
} else {
imageView . bounds = CGRectMake ( 0 , 0 , 20 , 20 ) ;
}
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 ;
2021-11-04 16:27:39 +08:00
}
2021-11-17 19:29:14 +08:00
2021-11-04 16:27:39 +08:00
// / 生 成 本 地 一 个 图 片 的 富 文 本
// / @ param imageName 网 络 图 片 的 地 址
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createLocalImageAttribute : ( NSString * ) imageName {
2021-11-17 19:29:14 +08:00
if ( imageName = = nil && imageName . length <= 0 ) {
return nil ;
}
2021-11-04 16:27:39 +08:00
return [ self createImageAttribute : [ UIImage imageNamed : imageName ] ] ;
}
// / 生 成 本 地 一 个 图 片 的 富 文 本
// / @ param image 本 地 的 图 片
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createImageAttribute : ( UIImage * ) image {
2021-11-04 16:27:39 +08:00
UIImageView * imaveView = [ [ UIImageView alloc ] init ] ;
imaveView . image = image ;
CGFloat scale = ( CGFloat ) imaveView . image . size . width / ( CGFloat ) imaveView . image . size . height ;
imaveView . bounds = CGRectMake ( 0 , 0 , 16 * scale , 16 ) ;
NSMutableAttributedString * attrString = [ NSMutableAttributedString yy_attachmentStringWithContent : imaveView contentMode : UIViewContentModeScaleAspectFit attachmentSize : CGSizeMake ( imaveView . frame . size . width , imaveView . frame . size . height ) alignToFont : [ UIFont systemFontOfSize : 15.0 ] alignment : YYTextVerticalAlignmentCenter ] ;
return attrString ;
}
// / 生 成 一 个 富 文 本
// / @ param text 富 文 本 的 文 字
// / @ param color 文 字 的 颜 色
// / @ param font 文 字 的 大 小
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createTextAttribute : ( NSString * ) text color : ( UIColor * ) color font : ( CGFloat ) font {
2021-11-17 19:29:14 +08:00
if ( text = = nil || text . length <= 0 ) {
text = @ "" ;
}
2021-11-04 16:27:39 +08:00
NSMutableAttributedString * attribute = [ [ NSMutableAttributedString alloc ] initWithString : text attributes : nil ] ;
attribute . yy_font = [ UIFont systemFontOfSize : font ] ;
attribute . yy_color = color ;
attribute . yy_paragraphStyle = [ self paragraphStyle ] ;
return attribute ;
}
// / 设 置 文 本 的 样 式 间 隙 缩 进 . . .
2021-11-26 21:47:00 +08:00
- ( NSMutableParagraphStyle * ) paragraphStyle {
2021-11-04 16:27:39 +08:00
NSMutableParagraphStyle * paraStyle = [ [ NSMutableParagraphStyle alloc ] init ] ;
paraStyle . lineSpacing = 4.0 f ; // 行 间 距
// 强 制 排 版 ( 从 左 到 右 )
paraStyle . alignment = NSTextAlignmentLeft ;
paraStyle . baseWritingDirection = NSWritingDirectionLeftToRight ;
return paraStyle ;
}
// / 占 位 的 富 文 本
// / @ param width 需 要 的 间 隙
2021-11-26 21:47:00 +08:00
- ( NSMutableAttributedString * ) createSapceAttribute : ( CGFloat ) width {
2021-11-04 16:27:39 +08:00
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 ;
}
@ end