8

UITableViewCell の Label 内のテキストのリンクを TTTAttributedLabel で検出したいのですが、うまくいきません。iOS8でswiftを使っています。以下はUITableViewCellコードです:

class StoryTableViewCell: UITableViewCell, TTTAttributedLabelDelegate {
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        // Link properties
        let textLabel = self.descriptionLabel
        let linkColor = UIColor(red: 0.203, green: 0.329, blue: 0.835, alpha: 1)
        let linkActiveColor = UIColor.blackColor()

        if (textLabel is TTTAttributedLabel) {
            var label = textLabel as TTTAttributedLabel
            label.linkAttributes = [NSForegroundColorAttributeName : linkColor]
            label.activeLinkAttributes = [NSForegroundColorAttributeName : linkActiveColor]        
            label.enabledTextCheckingTypes = NSTextCheckingType.Link.toRaw()

            label.delegate = self
        }
    }
}
4

5 に答える 5

3

UILabel のクラスとして TTTAttributedLabel を設定した場合は、ペン先またはストーリーボード内で、ユーザー インタラクションが有効になっていることを確認してください。デフォルトでは、UILabel ではユーザー インタラクションが無効になっています。

于 2016-07-19T02:57:45.690 に答える
0
    let linkColor = UIColor.blueColor()
    let linkActiveColor = UIColor.greenColor()

    textLabel.delegate = self

    textLabel.linkAttributes = [kCTForegroundColorAttributeName : linkColor.CGColor,kCTUnderlineStyleAttributeName : NSNumber(bool: true)]
    textLabel.activeLinkAttributes = [NSForegroundColorAttributeName : linkActiveColor]
    textLabel.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue
于 2015-09-12T07:41:55.417 に答える
0

最後に、commonInit() メソッドの TTTAttributedLabel.m に以下のコードを配置しました。

    self.enabledTextCheckingTypes = NSTextCheckingTypeLink;
于 2019-04-03T15:24:14.177 に答える