@@ -10,6 +10,7 @@
# import "KBAiChatMessage.h"
# import "KBChatHistoryPageModel.h"
# import "AiVM.h"
# import "KBImagePositionButton.h"
# import < Masonry / Masonry . h >
# import < SDWebImage / SDWebImage . h >
@@ -48,6 +49,12 @@
// / AiVM 实 例
@ property ( nonatomic , strong ) AiVM * aiVM ;
// / 评 论 按 钮
@ property ( nonatomic , strong ) KBImagePositionButton * commentButton ;
// / 喜 欢 按 钮
@ property ( nonatomic , strong ) KBImagePositionButton * likeButton ;
@ end
@ implementation KBPersonaChatCell
@@ -113,6 +120,24 @@
make . centerY . equalTo ( self . avatarImageView ) ;
} ] ;
// 评 论 按 钮 ( 最 右 侧 )
[ self . contentView addSubview : self . commentButton ] ;
[ self . commentButton mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . right . equalTo ( self . contentView ) . offset ( -20 ) ;
make . centerY . equalTo ( self . avatarImageView ) ;
make . width . mas_equalTo ( 40 ) ;
make . height . mas_equalTo ( 50 ) ;
} ] ;
// 喜 欢 按 钮 ( 评 论 按 钮 左 侧 , 间 距 20 px )
[ self . contentView addSubview : self . likeButton ] ;
[ self . likeButton mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . right . equalTo ( self . commentButton . mas_left ) . offset ( -20 ) ;
make . centerY . equalTo ( self . avatarImageView ) ;
make . width . mas_equalTo ( 40 ) ;
make . height . mas_equalTo ( 50 ) ;
} ] ;
// 聊 天 列 表
[ self . contentView addSubview : self . chatView ] ;
[ self . chatView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
@@ -147,6 +172,10 @@
// 关 键 修 复 : 清 空 消 息 时 停 止 音 频 播 放 , 避 免 状 态 混 乱
[ self . chatView stopPlayingAudio ] ;
[ self . chatView clearMessages ] ;
[ self . commentButton setTitle : persona . commentCount forState : UIControlStateNormal ] ;
[ self . likeButton setTitle : persona . likeCount forState : UIControlStateNormal ] ;
self . likeButton . selected = persona . liked ;
}
# pragma mark - 2 : 数 据 加 载
@@ -350,7 +379,7 @@
- ( UILabel * ) nameLabel {
if ( ! _nameLabel ) {
_nameLabel = [ [ UILabel alloc ] init ] ;
_nameLabel . font = [ UIFont boldSystemFontOfSize : 20 ] ;
_nameLabel . font = [ UIFont boldSystemFontOfSize : 1 2] ;
_nameLabel . textColor = [ UIColor whiteColor ] ;
_nameLabel . textAlignment = NSTextAlignmentCenter ;
}
@@ -377,4 +406,63 @@
return _chatView ;
}
- ( KBImagePositionButton * ) commentButton {
if ( ! _commentButton ) {
// 创 建 上 图 下 文 的 按 钮
_commentButton = [ [ KBImagePositionButton alloc ] initWithImagePosition : KBImagePositionTop spacing : 4 ] ;
// 关 键 修 复 : 先 设 置 字 体 , 再 设 置 文 字 , 避 免 循 环 调 用
_commentButton . titleLabel . font = [ UIFont systemFontOfSize : 10 ] ;
// 设 置 图 片
[ _commentButton setImage : [ UIImage imageNamed : @ "ai_comment_icon" ] forState : UIControlStateNormal ] ;
// 设 置 文 字
[ _commentButton setTitle : @ "0" forState : UIControlStateNormal ] ;
[ _commentButton setTitleColor : [ [ UIColor whiteColor ] colorWithAlphaComponent : 0.8 ] forState : UIControlStateNormal ] ;
// 添 加 点 击 事 件
[ _commentButton addTarget : self action : @ selector ( commentButtonTapped : ) forControlEvents : UIControlEventTouchUpInside ] ;
}
return _commentButton ;
}
- ( KBImagePositionButton * ) likeButton {
if ( ! _likeButton ) {
// 创 建 上 图 下 文 的 按 钮
_likeButton = [ [ KBImagePositionButton alloc ] initWithImagePosition : KBImagePositionTop spacing : 4 ] ;
// 关 键 修 复 : 先 设 置 字 体 , 再 设 置 文 字 , 避 免 循 环 调 用
_likeButton . titleLabel . font = [ UIFont systemFontOfSize : 10 ] ;
// 设 置 图 片
[ _likeButton setImage : [ UIImage imageNamed : @ "ai_live_icon" ] forState : UIControlStateNormal ] ;
[ _likeButton setImage : [ UIImage imageNamed : @ "ai_livesel_icon" ] forState : UIControlStateSelected ] ;
// 设 置 文 字
[ _likeButton setTitle : @ "0" forState : UIControlStateNormal ] ;
[ _likeButton setTitleColor : [ [ UIColor whiteColor ] colorWithAlphaComponent : 0.8 ] forState : UIControlStateNormal ] ;
// 添 加 点 击 事 件
[ _likeButton addTarget : self action : @ selector ( likeButtonTapped : ) forControlEvents : UIControlEventTouchUpInside ] ;
}
return _likeButton ;
}
# pragma mark - Button Actions
- ( void ) commentButtonTapped : ( KBImagePositionButton * ) sender {
sender . selected = ! sender . selected ;
NSLog ( @ "[KBPersonaChatCell] 评论按钮点击,选中状态:%d" , sender . selected ) ;
// TODO : 在 这 里 添 加 评 论 逻 辑
}
- ( void ) likeButtonTapped : ( KBImagePositionButton * ) sender {
sender . selected = ! sender . selected ;
NSLog ( @ "[KBPersonaChatCell] 喜欢按钮点击,选中状态:%d" , sender . selected ) ;
// TODO : 在 这 里 添 加 喜 欢 逻 辑
}
@ end