我一直在搜索这几个小时,但我失败了.我可能甚至不知道我应该寻找什么.
许多应用程序都有文本,在本文中是圆角矩形的Web超链接.当我点击它们UIWebView打开.让我感到困惑的是,他们经常有自定义链接,例如,如果单词以#开头,它也是可点击的,应用程序通过打开另一个视图来响应.我怎样才能做到这一点?是否有可能UILabel或我需要UITextView或其他什么?
hyperlink nsattributedstring uilabel ios uitapgesturerecognizer
我正在使用Interface Builder来布局我的应用程序.我有一个包含一些文本的UITextView,其中一部分是我想点击的URL(例如启动浏览器).我已经阅读了如何执行此操作并相信我正确地执行此操作,但是当URL显示为蓝色/可点击时,在iPhone模拟器中单击它不起作用.什么都没发生.
我的控制器:
@interface FirstViewController : UIViewController <UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UITextView *review;
@end
Run Code Online (Sandbox Code Playgroud)
在我的实现中我@synthesize review;(并且能够操纵视图的文本,所以不要认为这是问题).
在IB我有:

..然后,当我去设置文本(并尝试在视图中点击可用的URL)时,我这样做:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
Run Code Online (Sandbox Code Playgroud)
......显示如下内容:

...它看起来真的想要工作,但是点击URL时没有任何反应.我错过了什么?
--UPDATE--
尝试添加self.review.editable = NO;以回应Dixit Patel的回答,但它没有解决问题:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.editable = NO;
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
Run Code Online (Sandbox Code Playgroud) 我有一个UITextView横跨我的100.0分UIView.
在UITextView,我有链接,使用以下函数捕获:
- (BOOL) textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
Run Code Online (Sandbox Code Playgroud)
这非常适合捕获某些字符,但我有一个问题:如果链接是文本视图中的最后一个字符,那么点击将一直按到该行.
因此,如果我的文本视图中包含以下文本,其中@test是链接:
// The entire remainder of the line will be the link (all the white space after @test)
Hello @test
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我UITextView从三个标签(message,titleUrl和url)中显示并显示文本.我需要的是,我想让"titleUrl"文本可点击以在Web视图中打开"url"的值.我设法直接从网址打开链接,但我需要点击"titleUrl"打开链接.我试图从这段代码中实现以下功能.
[self buildAgreeTextViewFromString:NSLocalizedString(@"I agree to the #<ts>terms of service# and #<pp>privacy policy#",
@"PLEASE NOTE: please translate \"terms of service\" and \"privacy policy\" as well, and leave the #<ts># and #<pp># around your translations just as in the English version of this message.")];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何修改它来实现功能.我想在字符串中输入值,没有要输入的静态文本.任何人都可以指导我处理这件事吗?
更新:
NSString *message = [NSString stringWithFormat:@"%@\n ", tempStr1];
NSString *message1 = [NSString stringWithFormat:@"\n#<pp>%@#", titlStr1];
NSString *localizedString = NSLocalizedString(message1, nil);
NSRange ppRange = [localizedString rangeOfString:NSLocalizedString(message1, nil) options:NSCaseInsensitiveSearch];
NSURL *ppURL = [NSURL URLWithString:strUrl];
NSDictionary *attribute1 = @{NSForegroundColorAttributeName: …Run Code Online (Sandbox Code Playgroud) ios ×4
uitextview ×3
clickable ×1
hyperlink ×1
ios9 ×1
iphone ×1
nsurl ×1
objective-c ×1
uilabel ×1
url ×1