2012-10-16 46 views
4

我想創建一個對象,其中可以點擊文本。Xcode創建可點擊的文本

例如:我向用戶顯示文本: 「請在接受註冊之前驗證條款和條件。」

我想僅製作「條款和條件」文本顯示爲鏈接。文本將被強調爲藍色。

當用戶點擊文本我希望他們被導航到我的條款和條件視圖控制器頁面。所以鏈接是應用程序的內部鏈接,而不是外部網頁。

問題

  1. 如何顯示僅使特定的文本可鏈接的文本?
  2. 如何通過用戶點擊鏈接文本''seque'到ViewController頁面?
+0

你有什麼試過的?此外,您可以將文本設爲自定義按鈕並將文本顏色設置爲藍色。 – Josiah

回答

4

你可以用TTTAttributedLabel來做到這一點。自述文件:

除了支持富文本,TTTAttributedLabel允許您自動檢測URL,地址,電話號碼和日期的鏈接,或者允許您嵌入自己的鏈接。

label.dataDetectorTypes = UIDataDetectorTypeAll; // Automatically detect links when the label text is subsequently changed 
label.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol) 

label.text = @"Fork me on GitHub! (http://github.com/mattt/TTTAttributedLabel/)"; // Repository URL will be automatically detected and linked 

NSRange range = [label.text rangeOfString:@"me"]; 
[label addLinkToURL:[NSURL URLWithString:@"http://github.com/mattt/"] withRange:range]; // Embedding a custom link in a substring