TTTAttributedLabel可以检测到链接,但无法正确按下 [英] TTTAttributedLabel can detect links,but can't be pressed correctly
问题描述
我正在使用TTTAttributedLabel来检测链接,这是我初始化标签的代码:
I am using TTTAttributedLabel to detect links, here is the code I init the label:
- (TTTAttributedLabel *)getLinkLabelWithSize:(CGSize)size text:(NSString *)text{
TTTAttributedLabel *linkLabel;
linkLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(0, 0, size.width * 1.1, size.height)];
linkLabel.font = [UIFont systemFontOfSize:14.0f];
linkLabel.backgroundColor = [UIColor clearColor];
linkLabel.lineBreakMode = UILineBreakModeWordWrap;
linkLabel.numberOfLines = 0;
linkLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
linkLabel.delegate = self;
linkLabel.text = text;
return linkLabel;
}
我将标签添加到另一个视图(xxxView).
I add the label to anther view(xxxView).
CGSize size = [str sizeWithFont:fon constrainedToSize:CGSizeMake(150, 40)];
[returnView addSubview:[self getLinkLabelWithSize:size text:str]];
CGSize size = [str sizeWithFont:fon constrainedToSize:CGSizeMake(150, 40)];
[returnView addSubview:[self getLinkLabelWithSize:size text:str]];
这是标签委托方法:
#pragma mark - TTTAttributedLabelDelegate
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url {
[[UIApplication sharedApplication] openURL:url];
}
问题是我必须多次按下xxxView才能打开链接.我的代码有问题吗?
The problem is that I have to press the xxxView many times to open the link. It's there something wrong with my codes?
请问有人可以帮我吗.
推荐答案
检查您的单元格内容视图是否有TapGesture,如果是,请从短信单元格中删除Gesture
check if there is TapGesture for your cell content view,if yes, remove Gesture from the text message cell
这篇关于TTTAttributedLabel可以检测到链接,但无法正确按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!