【问题标题】:How to get selected URL when clicked on UITextView?单击 UITextView 时如何获取选定的 URL?
【发布时间】:2015-06-16 03:40:40
【问题描述】:

我的问题是当我点击其中包含的任何 URL 时,我想从 UITextView 获取 URL 字符串。

【问题讨论】:

    标签: ios uitextview


    【解决方案1】:
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    textView.dataDetectorTypes = UIDataDetectorTypeAll;
    textView.delegate = self; 
    
    // New in iOS 7
    - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { 
        if ([[URL scheme] isEqualToString:@"username"]) { 
            NSString *username = [URL host];  
            // do something with this username 
            // ... 
            return NO; 
        } 
        return YES; // let the system open this URL 
    } 
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多