7

有没有办法制作 UITextView 的可点击部分。其实我想让文字像

点击上方的“注册”,即表示您同意服务条款和隐私声明

其中服务条款应该是一个链接,而隐私声明应该是另一个链接。通过点击那些我应该做点什么。

4

1 回答 1

5

我使用这个项目用上面的代码做到了

- (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];
}
于 2013-01-15T13:30:11.527 回答