iOS可点击文本UITextView [英] iOS clickable text inside UITextView

查看:206
本文介绍了iOS可点击文本UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使UITextView的可点击部分。其实我想做文本

Is there a way to make clickable parts of UITextView. Actually I want to make text something like


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


By clicking "Register" above, you are agreeing to the Terms of Services and Privacy Statement

其中服务条款应为一个链接,隐私声明另一个链接。

where Terms of Services should be one link and Privacy Statement another. And by clicking on those I should do something.

推荐答案

我使用上面的代码使用此项目

I did it with the code above using 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];
}

这篇关于iOS可点击文本UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆