0

Clickable text is not sensitive when touching, need stay finger for a while to trigger that event. Is there a method to resolve that?

BollMose
  • 3,002
  • 4
  • 32
  • 41

1 Answers1

0

From our discussion in comments, I believe that you asked for a way to make part of String clickable. For this you can use NSAttributeString along with UITextView to resolve your problem.

NSString *myString = @"Sample string - click";
NSMutableAttributedString *myAttributedString = [[NSMutableAttributedString alloc] initWithString:myString];
[myAttributedString addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"randomString"] range:[initString rangeOfString:@"click"]];

UITextView *myNonEditableTextView = [[UITextView alloc] initWithFrame:CGRectMake(60, 200, [[UIScreen mainScreen] bounds].size.width - 120, 100)];
myNonEditableTextView.delegate = self;
myNonEditableTextView.attributedText = myAttributedString;
myNonEditableTextView.editable = NO;
[self.view addSubview: myNonEditableTextView];

// delegate functions for UITextView

// - For versions >= iOS 10, this delegate function should be used 
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
    [self performAction];
    return NO;
}

// - For versions < iOS 10, this delegate function should be used
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    [self performAction];
    return NO;
}

Hope this helps :) and let me know if you need a swift version.

KrishnaCA
  • 5,615
  • 1
  • 21
  • 31
  • Thank you for your answer, but I am sorry I change the title because I use UITextView not UILabel(UILabel cannot clickable automatically). – BollMose Nov 10 '16 at 13:35
  • That's great. My answer is for UITextView. Do you want a swift version for this? – KrishnaCA Nov 10 '16 at 14:37