【发布时间】:2015-06-16 03:40:40
【问题描述】:
我的问题是当我点击其中包含的任何 URL 时,我想从 UITextView 获取 URL 字符串。
【问题讨论】:
标签: ios uitextview
我的问题是当我点击其中包含的任何 URL 时,我想从 UITextView 获取 URL 字符串。
【问题讨论】:
标签: ios uitextview
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
}
【讨论】: