我正在尝试找到一种方法来使用第三方容器Active Label附加标签的用户名和注释文本。
我遇到的问题是一行label.text = "\(username) \(commentText)"
除非文本很长且能自动换行,否则效果很好,然后username
似乎保留,但commentText
会自动换行。如果注释简短,如何将username
和commentText
保持在同一行?
这是显示用户评论的代码
let customType = ActiveType.custom(pattern:"^\(username)\\b")
commentLabel.enabledTypes = [.hashtag, .mention, .url, customType]
commentLabel.configureLinkAttribute = { (type, attributes, isSelected) in
var atts = attributes
switch type {
case .custom:
atts[NSAttributedString.Key.font] = UIFont.boldSystemFont(ofSize: 13)
atts[NSAttributedString.Key.foregroundColor] = UIColor(named: "darkModeLabels")
default: ()
}
return atts
}
commentLabel.customize { (label) in
label.text = "\(username) \(commentText)"
label.customColor[customType] = UIColor(named:"darkModeLabels")
label.mentionColor = UIColor(named: "darkModeLabels")
label.font = UIFont.systemFont(ofSize: 13)
label.textColor = UIColor(named: "darkModeLabels")
}
但是UI显示如下:>
当我将label.text = "\(username) \(commentText)"
更改为label.text = "\(username)\(commentText)"
时>
我得到这个样子
[我正在尝试找到一种方法来使用第三方Pod Active Label附加标签的用户名和注释文本。我遇到的问题是一行label.text =“ \(用户名)\(commentText)” ...
设置
self.label.numberOfLines = 1