TTTAttributedLabel links are being styled but not clickable

后端 未结 2 1388
抹茶落季
抹茶落季 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:32

    The implementation of setAttributedText: doesn't update the linkModels array, while the implementation of setText: does. I believe this is what causes your issue.

    To resolve, set the label's text property instead of the attributedText property.

    The docs also include this warning:

    TTTAttributedLabel can display both plain and attributed text: just pass an NSString or NSAttributedString to the setText: setter. Never assign to the attributedText property.

    The docs also show this example usage:

    TTTAttributedLabel *attributedLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
    
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"Tom Bombadil"
                                                                    attributes:@{
            (id)kCTForegroundColorAttributeName : (id)[UIColor redColor].CGColor,
            NSFontAttributeName : [UIFont boldSystemFontOfSize:16],
            NSKernAttributeName : [NSNull null],
            (id)kTTTBackgroundFillColorAttributeName : (id)[UIColor greenColor].CGColor
    }];
    
    // The attributed string is directly set, without inheriting any other text
    // properties of the label.
    attributedLabel.text = attString;
    

提交回复
热议问题