Bla*_*rai 3 objective-c uitextview ios
我有一个UITextView里面有一个属性字符串,其中包含一个URL.属性字符串正在转换为链接,但是当您按下链接时会出现错误:
未知DDResult类别1的结果; 找不到网址www.myurl.com的任何操作
这是我的代码:
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"My Text", nil)];
NSRange range = [str.mutableString rangeOfString:@"www.myurl.com" options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"CourierPrime-Bold" size:15] range:NSMakeRange(0, range.location)];
[str addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"www.myurl.com"] range:range];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor brownColor] range:range];
}
self.welcomeText.editable = NO;
self.welcomeText.attributedText = str;
//As a note, I have tried this with the value 0 and UIDataDetectorTypeLink
//and neither option worked.
self.welcomeText.dataDetectorTypes = UIDataDetectorTypeAll;
Run Code Online (Sandbox Code Playgroud)
我正在使用XIB和我已selectable启用的行为选项,以及我links选择的检测选项.
我想在可能的情况下在手机移动浏览器中打开链接,而不是创建webview.
URL需要一个方案.
这个:
[str addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"www.myurl.com"] range:range];
Run Code Online (Sandbox Code Playgroud)
需要是:
[str addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.myurl.com"] range:range];
Run Code Online (Sandbox Code Playgroud)