如果文本较长,如何防止字符串换行

问题描述 投票:0回答:1

我正在尝试找到一种方法来使用第三方容器Active Label附加标签的用户名和注释文本。

我遇到的问题是一行label.text = "\(username) \(commentText)"

除非文本很长且能自动换行,否则效果很好,然后username似乎保留,但commentText会自动换行。如果注释简短,如何将usernamecommentText保持在同一行?

这是显示用户评论的代码


   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显示如下:>

enter image description here

当我将label.text = "\(username) \(commentText)"更改为label.text = "\(username)\(commentText)"时>

我得到这个样子

enter image description here

[我正在尝试找到一种方法来使用第三方Pod Active Label附加标签的用户名和注释文本。我遇到的问题是一行label.text =“ \(用户名)\(commentText)” ...

ios swift xcode label word-wrap
1个回答
0
投票

设置

self.label.numberOfLines = 1
© www.soinside.com 2019 - 2024. All rights reserved.