我的问题是,当我访问其中包含的任何网址时,我想从UITextView获取URL字符串。
答案 0 :(得分:0)
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
}