Clickable text is not sensitive when touching, need stay finger for a while to trigger that event. Is there a method to resolve that?
Asked
Active
Viewed 198 times
0
-
This is the default behaviour of UILabel with a link or any actionable item. – Rajan Balana Nov 10 '16 at 05:09
-
You can try using this custom library or component. https://github.com/TTTAttributedLabel/TTTAttributedLabel – Rajan Balana Nov 10 '16 at 05:11
-
Do you want a clickable UILabel or a part of string in UILabel that's clickable? – KrishnaCA Nov 10 '16 at 05:41
-
Instead of UILabel you can use UIButton. Hopes it will helps you – Gourav Joshi Nov 10 '16 at 05:44
-
@KrishnaChaitanyaAmjuri part of string can be clickable. – BollMose Nov 10 '16 at 07:30
-
If that's what you want, you can check my answer – KrishnaCA Nov 10 '16 at 09:13
-
@BollMose, you said `need stay finger for a while to trigger that event`. Does that mean you are looking for Long Press Recognizer on part of String on UITextView? – KrishnaCA Nov 10 '16 at 18:15
-
I need a sensitive style as UIButton. @KrishnaChaitanyaAmjuri – BollMose Nov 11 '16 at 03:35
-
Does that mean one click on string triggers a method? or do you need all UIControlEvents that are there for UIButton? – KrishnaCA Nov 11 '16 at 05:39
1 Answers
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