如何使 ReadMoreTextView 库中的 attributedReadMoreText 不可选 - swift

How to make `attributedReadMoreText` in `ReadMoreTextView` library not selectable - swift

我是新手iOS编程。现在我正在创建一个示例应用程序,它使用 ReadMoreTextView 库显示文本。我的内容可能包含很多行,但通过使用这个库,我可以 maximumNumberOfLines 显示应该显示多少行内容。我在 UITableViewcell 中实现了这些内容,我的问题是,当我使用 label.attributedReadMoreText = NSAttributedString(string: "...") 时,内容的结尾将显示 ...,当我单击它时,然后整个内容都会这样显示,我的问题是:如何不让用户点击 ... 因为我希望用户点击 cell 然后我会显示另一个视图并在那里显示整个内容?

我怎样才能实现这样的目标?提前致谢。

我是这样设置的UITextView

lazy var categoryShortDetailLabel: ReadMoreTextView = {

    let label = ReadMoreTextView()
    label.font = UIFont(name: "SFCompactText-Regular", size: 16)
    label.textColor = .black
    label.isEditable = false
    label.isSelectable = false
    label.maximumNumberOfLines = 3
    label.shouldTrim = true
    label.attributedReadMoreText = NSAttributedString(string: "...")

    label.translatesAutoresizingMaskIntoConstraints = false

    return label

}()

查看代码 here,我发现 ReadMoreTextView 旨在为您提供类似 ReadMore[=24= 的功能] 和 ReadLess 用于 textView 中较大的文本。

但是您的要求是停止该功能。现在,如果你看一下 code here, you will get the idea, that the function shoreMoreText and it's a private function so, can't override it. and this function is expanding the texts and setting the numberOfLines to zero. so, what you can do is, comment the code within and return from function to stop doing the action. Also as the ReadMoreTextView is Licensed as MIT(Read licence here) 所以,修改代码就可以了。

private func showMoreText() {
    return
    /*if let readLessText = readLessText, text.hasSuffix(readLessText) { return }
    
    shouldTrim = false
    textContainer.maximumNumberOfLines = 0

    if let originalAttributedText = _originalAttributedText?.mutableCopy() as? NSMutableAttributedString {
        attributedText = _originalAttributedText
        let range = NSRange(location: 0, length: text.count)
        if let attributedReadLessText = attributedReadLessText {
            originalAttributedText.append(attributedReadLessText)
        }
        textStorage.replaceCharacters(in: range, with: originalAttributedText)
    }
    
    invalidateIntrinsicContentSize()
    invokeOnSizeChangeIfNeeded()*/
}

尝试并分享您的结果。

希望对您有所帮助!