2010-11-21 38 views

回答

0

您可以使用UITextView啓用dataDetectorTypes,以便檢測URL(和其他常用鏈接)並自動鏈接到其默認應用程序。

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero]; 
text.dataDetectorTypes = UIDataDetectorTypeLink; // see below for other options 

這裏https://developer.apple.com/library/content/qa/qa1495/_index.html

0

從iOS7後來其他dataDetectorTypes選項看到蘋果文檔現在它變得更加容易地檢測UITextView鏈接。

UITextView *txtView=[[UITextView alloc]initWithFrame:CGRectMake(0, 10, 320, 500)]; 
txtView.delegate=self; 
txtView.dataDetectorTypes = UIDataDetectorTypeLink; 

實現此委託方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{ 

    // do what ever you want 
    return YES; 
} 
相關問題