2013-01-15 25 views
7

Có cách nào để tạo các phần có thể nhấp của UITextView không. Thật sự tôi muốn làm một cái gì đó văn bản nhưVăn bản có thể nhấp của iOS bên trong UITextView

Bằng cách nhấp “Đăng ký” ở trên, bạn đồng ý với Điều khoản dịch vụ và bảo mật thông

nơi Điều khoản của dịch vụ nên một liên kết và bảo mật thông khác . Và bằng cách nhấp vào những người tôi nên làm một cái gì đó.

+1

nếu nó là có thể trong bạn ứng dụng, bạn có thể sử dụng 'đối tượng UIWebView' với một định dạng 'nội dung HTML', và tất cả mọi thứ có thể nhấp chuột, và bạn sẽ có thể xử lý tất cả chúng trong ứng dụng của bạn. – holex

+0

Vâng, tôi biết rằng giải pháp, nhưng đó là một số loại hack :) và tôi muốn có một số giải pháp thanh lịch hơn. Cảm ơn bạn! – zvjerka24

+0

nó là rất tốn kém và giải pháp mạnh mẽ, nếu thời gian không quan trọng ... :) – holex

Trả lời

5

tôi đã làm nó với đoạn code trên sử dụng 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

Hoạt động tốt nhờ! – zvjerka24

+0

vui vì nó giúp bạn, cảm ơn cho đánh dấu là câu trả lời đúng – tkanzakic

+0

Vì vậy, bạn đã không sử dụng UITextView. Có thể làm gì với UITextView không? – NSGodMode

Các vấn đề liên quan