Is it possible to detect CGRect
of link text or CGPoint
of position, to show popover (on ipad) for clicked link in TTTAttributedLabel
?
I need to show popover on clicked link with TTTAttributedLabel
.
Thanks!
Is it possible to detect CGRect
of link text or CGPoint
of position, to show popover (on ipad) for clicked link in TTTAttributedLabel
?
I need to show popover on clicked link with TTTAttributedLabel
.
Thanks!
You can only do this by modifying the TTTAttributedLabel to support this behavior.
1) Modify the delegate method:
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url
atPoint:(CGPoint)point;
2) In the TTTAttributedLabel.m
source, modify the touchesEnded:withEvent:
and grab the touch point and pass this onto the delegate method.
switch (result.resultType) {
case NSTextCheckingTypeLink:
if ([self.delegate respondsToSelector:@selector(attributedLabel:didSelectLinkWithURL:atPoint:)]) {
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
[self.delegate attributedLabel:self didSelectLinkWithURL:result.URL atPoint:touchPoint];
return;
3) In the view controller, you will need to convert that touch point to be in relative coordinates to the view controller's view:
#pragma mark TTTAttributedLabelDelegate
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url
atPoint:(CGPoint)point
{
CGPoint normalizedPoint = [self convertPoint:point fromView:label];
UIActionSheet *actionSheet = [[UIActionSheet alloc] ...
[actionSheet showFromRect:CGRectMake(normalizedPoint.x, normalizedPoint.y-kSensibleOffset, 10, 10)
inView:label
animated:YES];
}
#pragma mark -
You don't want to do this at the gesture level by trying to keep track of position. Since you have a link, just override openURL
and do whatever you want when you intercept the link click. More details are here.