UITextView link is not clickable iOS 8

I followed this: UILabel and NSLinkAttributeName: the link does not click and the UITextView link is clickable, but when I click it, Safari does not open , but to no avail.

I have:

uitextView.attributedText = ... some attributed string "http://google.com" ... 

Link Detection, Optional, and User Engagement Enabled are included. "editable" is disabled.

I also implemented a UITextViewDelegate

 - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)url inRange:(NSRange)characterRange { return YES; } 

However, the link appears in blue, but when I click, nothing happens.

+5
source share
2 answers

I had the same problem. Nothing helped.

The problem was that I added a UITextView to ScrollView and then used sizeToFit .

For example: I had view.frame (0,0,320,440). And ScrollView contentSize (0,0,320,1000) And the links in view.frame work, but when you scroll down - not.

Than I tried to check which view is selected when scrolling down and click on UITextView. I added UITapGestureRecognizers and found out that when I touch the self.view framework within a UITextView, it uses a UITextView. But when I scroll down - click on "Mark", as tap ScrollView. In other words, it looks like a frame of UITextView clips in the framework of self.view.

EDIT: I found the problem:

I had a hierarchy of View - ScrollView - ContentView - Elements . Thus, there was a time when ScrollView was larger than ContentView, so the link can only be used within the ContentView. To fix this , I removed the ContentView and placed all the elements in the ScrollView. Hope this answer helps someone :)

+2
source

Try this approach:

 NSString *clickMe = [NSString stringWithFormat:@"%@", word]; NSMutableAttributedString * str2 = [[NSMutableAttributedString alloc] initWithString:word]; [str2 addAttribute: NSLinkAttributeName value:[NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@",linkWord]] range:NSMakeRange(0, clickMe.length)]; // replace with link [YourAttributedString replaceCharactersInRange:wordRange withAttributedString:str2]; 
+1
source

All Articles