我有iOS应用程序,在一个字符串中,我有这样的文字和链接
文本文本文本文本文本 http:// mylink.com 文本文本文本文本文本
是否可以识别该链接并使其正常工作?
由于
答案 0 :(得分:0)
在UITextView中,查看dataDetectorTypes
UITextView *test = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, 150.0f, 320.0f, 200.0f)];
test.text = @"Some text http://www.yahoo.com/ more text";
test.editable = NO;
test.dataDetectorTypes = UIDataDetectorTypeLink;
[self addSubview:test];
该字符串中的链接将为蓝色并带下划线,当点按时,它将在Safari中启动。您可以检测到更多这样的信息:
test.dataDetectorTypes = UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;