2012-07-30 54 views
1

在我的應用程序中,我想要一個文本或一個字符串,在UITextView中存在。點擊它應該連接到任何網址可以說,「www.google.com」。問題是,當我點擊UITextView中的文本時,它不會被點擊。我該怎麼辦 ?自2天以來我被困,請幫助我。如何在UITextView中創建單詞或文本?

+0

你能發佈你已經試過的代碼嗎? – thegrinner 2012-07-30 12:46:37

回答

1

您需要添加按鈕,例如goToWebSiteButton放在你的UITextView的頂部。

@property (weak, nonatomic) IBOutlet UIButton *goToWebSiteButton; 

然後合成它:

@synthesize goToWebSiteButton; 

然後添加目標按鈕:如果您在爲UITextField挖掘

[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]; 

} 
+0

非常感謝您的信息 – khadar 2012-07-31 07:12:14

+0

現在我的代碼正在工作 – khadar 2012-07-31 07:12:38

+0

接受答案,如果它幫助,請 – Alex 2012-07-31 07:22:42

0

首先,它會被竊聽,因爲它意在由用戶輸入任何文本。如果您想連接到網址,只需將UIWebView方法添加到您的UITextfield方法。

最好是,在用戶輸入任何內容後,將其放入UILabelUIButton,並在其點擊或點按讓其打開UIWebView。

0

您可以使用UIWebView,並可以在那裏製作超鏈接。
或者您可以使用TTTAttributedLabel,它可以容納NSAttributedString
或者您可以清除UIButton以上的文字。

相關問題