TTTAttributedLabel links are being styled but not clickable

后端 未结 2 1403
抹茶落季
抹茶落季 2020-12-31 20:48

I\'ve been looking into a solution to getting clickable links working. I can get this working when using UITextView + NSAttributedString but it just doesn\'t autolayout prop

2条回答
  •  既然无缘
    2020-12-31 21:12

    Aaron Brager is correct! I used to have the same problem, but I got it fixed in Swift by replacing the line:

    label.attributedText = attributedString
    

    with the line:

    label.setText(attributedString)
    

    This is accepted by the compiler because the setText method accepts AnyObject. I also increased the font of the attributed string of the link so it captures my tap and it is working now! I used this for the truncation link, this is the whole part:

    label.lineBreakMode = .ByTruncatingHead
    label.attributedTruncationToken = NSMutableAttributedString(string: "... Show more", attributes: [NSForegroundColorAttributeName: UIColor.cueCyan(), NSLinkAttributeName: readMoreLink, NSFontAttributeName: UIFont.formFont(.Light, size: fontSize+24)!])
    label.userInteractionEnabled = true
    label.delegate = self
    

提交回复
热议问题