在我的应用程序中,我希望点击 UITextView 中的文本或字符串。点击后它应该连接到任何网址,比如说“www.google.com”。问题是,当我在 UITextView 中点击文本时,它没有被点击。我应该怎么办 ?我被困了两天,请帮帮我。
问问题
701 次
3 回答
1
您需要在 UITextView 顶部添加按钮,例如 goToWebSiteButton。
@property (weak, nonatomic) IBOutlet UIButton *goToWebSiteButton;
然后合成它:
@synthesize goToWebSiteButton;
然后将目标添加到按钮:
[goToWebSiteButton addTarget:self action:@selector(goToWebSite:event:) forControlEvents:UIControlEventTouchUpInside];
- (void)goToWebSite:(id)sender event:(id)event{
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://%@", @"www.google.com" ]];
[[UIApplication sharedApplication] openURL:url];
}
于 2012-07-30T12:50:17.210 回答
0
您可以UIWebView
在那里使用并且可以制作超链接。
或者您可以使用TTTAttributedLabel可以保存或者您可以在要单击的文本上NSAttributedString
清除's。UIButton
于 2012-07-30T12:59:24.507 回答
0
首先,如果您点击 UITextfield ,它将被点击,因为它意味着用户输入任何文本。如果您想连接到一个 url,只需将该UIWebView
方法添加到您的UITextfield
方法中即可。
最好是在用户输入任何内容后,将UITextfield
其放入 aUILabel
或 aUIButton
中,然后单击或点击,让它打开 UIWebView。
于 2012-07-30T12:54:43.913 回答