Mitesh Khatri
Mitesh Khatri

Reputation: 3955

Detect Click on nsurl on uitextview

I have a URL in my textview and when we click on this url it opens this url in default safari. and I want to detect this event. I also tried this

but its not working for me. can any one suggest me how i do this. Provide me a sample for this.

My application deligate is UIResponder type.

Upvotes: 2

Views: 3157

Answers (3)

featherless
featherless

Reputation: 2141

Assuming you just need to display a static label with links, we have a fairly powerful attributed label in Nimbus that you may wish to check out:

http://docs.nimbuskit.info/group___nimbus_attributed_label.html

The label uses CoreText and NSAttributedString, so it is built on core Apple technologies. It acts in every way like a UILabel. Here's an example of implementing the NIAttributedLabel delegate:

https://github.com/jverkoey/nimbus/blob/master/examples/attributedlabel/BasicAttributedLabel/BasicAttributedLabel/src/MashupViewController.m#L92

More info: http://nimbuskit.info/

Upvotes: 0

user207616
user207616

Reputation:

the other answer works as expected.

create New File, select Objective-C Class

  • Class: MyApplication
  • Subclass of: UIApplication

paste this code in the .m file:

- (BOOL)openURL:(NSURL *)url {
    if  ([self handleOpenURL:url])
        return YES;
    else
        return [super openURL:url];
}
- (BOOL)handleOpenURL:(NSURL*)url {
    NSLog(@"my url handler");
    return YES;
}

next open your main.m and change the third parameter

return UIApplicationMain(argc, argv, nil, NSStringFromClass([SampleAppDelegate class]));

to your UIApplication-subclass name

return UIApplicationMain(argc, argv, @"MyApplication", NSStringFromClass([SampleAppDelegate class]));

Upvotes: 2

Mat
Mat

Reputation: 7633

Take a look at this GitHub project: MSTextView

Upvotes: 0

Related Questions