I have an NSTextView with automatic link detection enabled. When I set the text programmatically [myTextView setString:@"http://google.com"]
it doesn't automatically show the link.
If I type anything into the text view it will add the link. I want it to add the link
Had to spent some time searching for solution, but could not find it anywhere.
You do not need any third party libraries. Cocoa will do it for you.
checkTextInDocument: works only on editable textViews (Apple forgot to mention this). Here is code which works if your NSTextView is read only:
[myTextView setEditable:YES];
[myTextView checkTextInDocument:nil];
[myTextView setEditable:NO];
Do not forget to check "Smart links" in your .xib file
I ended up adding a category that would do the job. It relies on a couple other categories for finding and formatting links.
I wrote a blog post about it here.
I also put a sample project up on GitHub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With