2013-01-15 74 views
7

有沒有辦法讓UITextView的可點擊部分。其實我想使文本類似UITextView中的iOS可點擊文本

點擊「註冊」之上,即表示您同意的服務條款和隱私權聲明

其中服務條款應該是一個鏈接,隱私聲明另一個。點擊那些我應該做的事情。

+1

如果是在你的應用程序有可能,你可以使用'UIWebView'對象與格式'HTML'內容,一切都可以點擊,和你將能夠處理你的應用程序中的所有人。 – holex

+0

是的,我知道這個解決方案,但它是某種破解:)我想要一些更優雅的解決方案。 謝謝! – zvjerka24

+0

它是非常無代價和強大的解決方案,如果時間確實重要... :) – holex

回答

5

我做到了與上面的代碼中使用this project

- (void)_configureTermsLabel 
{ 
    self.termsOfUseLabel.hidden = YES; 
    self.termsAndConditionsLabel = [[TTTAttributedLabel alloc] initWithFrame:self.termsOfUseLabel.frame]; 
    self.termsAndConditionsLabel.font = [UIFont systemFontOfSize:14]; 
    self.termsAndConditionsLabel.lineBreakMode = UILineBreakModeWordWrap; 
    self.termsAndConditionsLabel.numberOfLines = 0; 

    NSString *termsStr = NSLocalizedString(@"Terms of use", @"Terms of use"); 
    NSString *privacyStr = NSLocalizedString(@"Privacy Policy", @"Privacy Policy"); 
    NSString *andStr = NSLocalizedString(@"and", @"and"); 
    NSString *conductStr = NSLocalizedString(@"Code of conduct", @"Code of conduct"); 
    NSString *termsAndConditionsStr = [NSString stringWithFormat:@"%@ - %@ %@ %@", termsStr, 
             privacyStr, andStr, conductStr]; 
    self.termsAndConditionsLabel.text = termsAndConditionsStr; 

    NSString *languageCode = [[GLQAppDelegate sharedDelegate] languageIdentifier]; 
    NSURL *termsURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQTermsOfUseURL, languageCode]]; 
    NSURL *privacyURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQPrivacyPolicyURL, languageCode]]; 
    NSURL *conductURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQCodeOfConductURL, languageCode]]; 

    NSRange termsRange = [self.termsAndConditionsLabel.text rangeOfString:termsStr]; 
    NSRange privacyRange = [self.termsAndConditionsLabel.text rangeOfString:privacyStr]; 
    NSRange conductRange = [self.termsAndConditionsLabel.text rangeOfString:conductStr]; 

    [self.termsAndConditionsLabel addLinkToURL:termsURL withRange:termsRange]; 
    [self.termsAndConditionsLabel addLinkToURL:privacyURL withRange:privacyRange]; 
    [self.termsAndConditionsLabel addLinkToURL:conductURL withRange:conductRange]; 
    self.termsAndConditionsLabel.delegate = self; 

    self.termsAndConditionsLabel.userInteractionEnabled = YES; 
    [self.scrollView addSubview:self.termsAndConditionsLabel]; 
} 
+0

工程很好,謝謝! – zvjerka24

+0

很高興它可以幫助你,謝謝你標記爲正確的答案 – tkanzakic

+0

所以你沒有使用UITextView。用UITextView做不可能嗎? – NSGodMode