swiftuitableviewuitextviewiosdeployment

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


I am a new iOS programming. Now i am creating a sample app which display text using ReadMoreTextView library. My content may contain many lines but by using this library i can maximumNumberOfLines to display how many lines of content should be displayed. I implement those content in cell of UITableView and i have problem is that, when i use label.attributedReadMoreText = NSAttributedString(string: "...") then end of content will display ... and when i click on it and then whole content will be display so, my question is that: How to not letting user click on that ... because i want user to click on cell then i will show another view and display whole content there?

How can i achieve something like this? Thank in advance.

This is how i set 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

}()

Solution

  • Looking at the code here, I found that, the ReadMoreTextView is meant to provide you the feature like, ReadMore and ReadLess for the larger texts in textView.

    However your requirement is to stop that functionality. Now, if you take a look at the 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) so, it's okay to modify the code.

    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()*/
    }
    

    Try and share your results.

    Hope it helps!