gpt4 book ai didi

ios - UITextView.attributedText,如何设置numberOflines和lineBreakMode?

转载 作者:搜寻专家 更新时间:2023-11-01 07:06:33 32 4
gpt4 key购买 nike

在某些情况下,我必须使用 UITextView 而不是 UILabel(使链接属性可点击)。这是我的代码:

    let attributedString = NSMutableAttributedString(string: "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest")
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byTruncatingTail
attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))

这是我的 TextView :

private lazy var titleTextView: UITextView = {
let view = UITextView(frame: .zero, textContainer: nil)
view.isEditable = false
view.textContainerInset = .zero
view.textContainer.lineFragmentPadding = 0
view.textContainer.maximumNumberOfLines = 2 // Set numberOflines here!
view.textAlignment = .left
view.isScrollEnabled = false
view.delegate = self

return view
}()

但是 maximumNumberOfLines 属性不起作用,它只显示 1 行,然后是“...”

enter image description here

最佳答案

您需要将 lineBreakMode 设置为不截断的值。

尝试

paragraphStyle.lineBreakMode = .byWordWrapping

关于ios - UITextView.attributedText,如何设置numberOflines和lineBreakMode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47746131/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com