Commit 9a06c24b authored by Steven杜宇's avatar Steven杜宇

// AI

parent 2a84e42d
...@@ -382,14 +382,24 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource ...@@ -382,14 +382,24 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
if msgType != .text { if msgType != .text {
return UITableView.automaticDimension return UITableView.automaticDimension
} }
let text = message.body.contentText // 要显示的文本内容
let font = UIFont.PFSC_R(ofSize: 14) // 字体大小
let maxWidth = KScreenWidth-20*2-16*2 // 最大宽度限制
let attributes = [NSAttributedString.Key.font : font] as [NSAttributedString.Key : Any] let label = UILabel()
let size = (text as NSString).boundingRect(with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size label.textAlignment = .left
label.font = UIFont.PFSC_R(ofSize:14)
label.numberOfLines = 0
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4.0
let attributedText = NSAttributedString(
string: message.body.contentText,
attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.PFSC_R(ofSize:14)]
)
label.attributedText = attributedText
let maxWidth = KScreenWidth-20*2-16*2 // 最大宽度限制
let size = label.sizeThatFits(CGSize(width: maxWidth, height: .greatestFiniteMagnitude))
var textHeight = ceil(size.height) var textHeight = ceil(size.height)
if textHeight < 20.0 { if textHeight < 20.0 {
textHeight = 20.0 textHeight = 20.0
......
...@@ -516,14 +516,24 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc ...@@ -516,14 +516,24 @@ extension YHAIRobotChatViewController: UITableViewDelegate, UITableViewDataSourc
if msgType != .text { if msgType != .text {
return UITableView.automaticDimension return UITableView.automaticDimension
} }
let text = message.body.contentText // 要显示的文本内容
let font = UIFont.PFSC_R(ofSize: 14) // 字体大小
let maxWidth = KScreenWidth-20*2-16*2 // 最大宽度限制
let attributes = [NSAttributedString.Key.font : font] as [NSAttributedString.Key : Any] let label = UILabel()
let size = (text as NSString).boundingRect(with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size label.textAlignment = .left
label.font = UIFont.PFSC_R(ofSize:14)
label.numberOfLines = 0
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4.0
let attributedText = NSAttributedString(
string: message.body.contentText,
attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.PFSC_R(ofSize:14)]
)
label.attributedText = attributedText
let maxWidth = KScreenWidth-20*2-16*2 // 最大宽度限制
let size = label.sizeThatFits(CGSize(width: maxWidth, height: .greatestFiniteMagnitude))
var textHeight = ceil(size.height) var textHeight = ceil(size.height)
if textHeight < 20.0 { if textHeight < 20.0 {
textHeight = 20.0 textHeight = 20.0
......
...@@ -18,15 +18,22 @@ class YHAITextMessageCell: UITableViewCell { ...@@ -18,15 +18,22 @@ class YHAITextMessageCell: UITableViewCell {
var message: YHAIChatMessage = YHAIChatMessage() { var message: YHAIChatMessage = YHAIChatMessage() {
didSet { didSet {
messageLabel.text = message.body.contentText let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4.0
let textColor: UIColor = message.isSelf ? .white : .mainTextColor
let attributedText = NSAttributedString(
string: message.body.contentText,
attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.font: UIFont.PFSC_R(ofSize:14)]
)
messageLabel.attributedText = attributedText
rightAngleView.backgroundColor = message.isSelf ? .brandMainColor : .white rightAngleView.backgroundColor = message.isSelf ? .brandMainColor : .white
rightAngleView.isHidden = message.getType() != .text rightAngleView.isHidden = message.getType() != .text
if message.isSelf { if message.isSelf {
whiteContentView.backgroundColor = .brandMainColor whiteContentView.backgroundColor = .brandMainColor
messageLabel.textColor = .white
whiteContentView.snp.remakeConstraints { make in whiteContentView.snp.remakeConstraints { make in
make.left.greaterThanOrEqualTo(20) make.left.greaterThanOrEqualTo(20)
make.right.equalTo(-20) make.right.equalTo(-20)
...@@ -45,11 +52,7 @@ class YHAITextMessageCell: UITableViewCell { ...@@ -45,11 +52,7 @@ class YHAITextMessageCell: UITableViewCell {
} else { } else {
messageLabel.text = message.body.contentText
whiteContentView.backgroundColor = .white whiteContentView.backgroundColor = .white
messageLabel.textColor = .mainTextColor
whiteContentView.snp.remakeConstraints { make in whiteContentView.snp.remakeConstraints { make in
make.left.equalTo(20) make.left.equalTo(20)
if message.getType() == .recommendText { if message.getType() == .recommendText {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment