Skip to content

truncationToken的值设置无效 #20

Description

@lxm1799

使用BSText实现文本展开收缩的时候,设置truncationToken值,打印string值显示为空。
代码:
func addSeeMoreActionWithText(text:String,label:BSLabel,font:UIFont,isMore:Bool) -> NSAttributedString {

    label.attributedText = text.withAttributes([.font(font),.textColor(.Color101010)])
    
    let moreStr = isMore ? "收起":"查看全部"
    let moreAttributedText = NSMutableAttributedString.init(string: "..." + moreStr)
    
    let moreTextRange = NSRange(location: 3, length: moreStr.count)
    moreAttributedText.addAttributes([.font(font),.textColor(.Color101010)], range: NSRange(location: 0, length: 2))
    moreAttributedText.addAttributes([.font(font),.textColor(.red)], range: moreTextRange)
    
    let textHighlight = TextHighlight()
    moreAttributedText.bs_set(textHighlight: textHighlight, range: moreTextRange)
    textHighlight.tapAction = {(containerView,text,range,rect) in
        print("2222")
    }
    
    moreAttributedText.bs_font = font
    let seeMoreLabel = BSLabel()
    seeMoreLabel.attributedText = moreAttributedText
    seeMoreLabel.sizeToFit()

    let truncationToken = NSAttributedString.bs_attachmentString(with: seeMoreLabel, contentMode: .center, attachmentSize: seeMoreLabel.frame.size, alignTo: font, alignment: .top)
    
    print("\(String(describing: truncationToken?.string)),\(truncationToken?.mutableString)")
    
    if truncationToken != nil {
        label.truncationToken = truncationToken
        return truncationToken!
    }
    return NSAttributedString()
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions