本文介绍了TTTAttributedLabel代表didSelectLinkWithURL没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在自定义单元格中设置 TTTAttributedLabel
时遇到问题.我已经检查了许多帖子,但仍然不知道如何解决此问题.(我可以在此自定义标签上看到URL样式,但是如果单击它,则什么也没有发生.)
I'm having problem setting up the TTTAttributedLabel
within my custom cell. I have already checked many post and still didn't figured how to solve this. (I can see the URL styling at this custom label , but if i click on it nothing happen).
CustomCell.h:
@interface MyCustomCell : UITableViewCell<TTTAttributedLabelDelegate>
@property (nonatomic, strong, readonly) UITapGestureRecognizer *tapRecognizer;
@property (nonatomic, strong, readonly) UILabel *senderLabel;
@property (nonatomic, strong, readonly) UILabel *timeLabel;
@property (nonatomic, strong, readonly) UILabel *dateLabel;
@property (nonatomic, strong) TTTAttributedLabel *customTextLabel;
@end
CustomCell.m:
@implementation MyCustomCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
_dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_dateLabel.textAlignment = NSTextAlignmentCenter;
_dateLabel.font = [UIFont boldSystemFontOfSize:12.0];
_dateLabel.textColor = [UIColor grayColor];
_dateLabel.text = @"2015-10-10";
_dateLabel.userInteractionEnabled = false;
_senderLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_senderLabel.textAlignment = NSTextAlignmentLeft;
_senderLabel.font = [UIFont boldSystemFontOfSize:14.0];
_senderLabel.textColor = [UIColor whiteColor];
_senderLabel.userInteractionEnabled = false;
_timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_timeLabel.userInteractionEnabled = false;
_timeLabel.textAlignment = NSTextAlignmentCenter;
_timeLabel.font = [UIFont boldSystemFontOfSize:11.0];
_timeLabel.textColor = [UIColor whiteColor];
_customTextLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
_customTextLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
_customTextLabel.delegate = self;
_customTextLabel.backgroundColor = [UIColor clearColor];
_customTextLabel.numberOfLines = 0;
_customTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
_customTextLabel.textColor = [UIColor blackColor];
_customTextLabel.font = [UIFont systemFontOfSize:18.0];
[self.textLabel addSubview:_customTextLabel];
_customTextLabel.userInteractionEnabled = true;
self.imageView.userInteractionEnabled = YES;
self.imageView.layer.cornerRadius = 5.0;
self.imageView.layer.masksToBounds = YES;
}
return self;
}
感谢您的帮助.
推荐答案
NSString *text = @"Hello this is https://www.google.com";
_customTextLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(0, 100, 300, 20)];
_customTextLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
_customTextLabel.delegate = self;
_customTextLabel.backgroundColor = [UIColor clearColor];
_customTextLabel.numberOfLines = 0;
_customTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
_customTextLabel.textColor = [UIColor blackColor];
_customTextLabel.font = [UIFont systemFontOfSize:18.0];
_customTextLabel.text = text;
[self.view addSubview:_customTextLabel];
并设置 TTTAttributedLabel
的委托方法可以正常工作,请检查:
And set delegate method of TTTAttributedLabel
it works fine please check:
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
}
这篇关于TTTAttributedLabel代表didSelectLinkWithURL没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!