美文网首页
TTTAttributedLabel 使用小记

TTTAttributedLabel 使用小记

作者: 单纯的敲代码 | 来源:发表于2018-12-26 22:34 被阅读0次
        NSString * strDesc = @"请您认真阅读《注册条款》、《隐私策略》并同意后点击勾选,我们将尽全力保护您的个人信息安全。";
        lblActicle.font = font;
        lblActicle.textColor = color;
        lblActicle.delegate = self;
        lblActicle.lineSpacing = 4;
        lblActicle.enabledTextCheckingTypes = NSTextCheckingTypeLink;
        [lblActicle setText:strDesc afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
            return mutableAttributedString;
        }];
        
        //设置可点击文字的颜色和去除下划线
        lblActicle.linkAttributes = @{(NSString *)kCTForegroundColorAttributeName:color_LinkURL,
                                        (NSString *)kCTUnderlineStyleAttributeName:[NSNumber numberWithBool:NO]};
        //设置点击时文字的颜色
        lblActicle.activeLinkAttributes =@{(NSString *)kCTForegroundColorAttributeName:[color_LinkURL colorWithAlphaComponent:0.6]};
        
        //设置点击文字
        [lblActicle addLinkToURL:[NSURL URLWithString:RegisterUrl] withRange:[strDesc rangeOfString:@"《注册条款》"]];
        [lblActicle addLinkToURL:[NSURL URLWithString:StatementUrl] withRange:[strDesc rangeOfString:@"《隐私策略》"]];
    
    #pragma mark - TTTAttributedLabelDelegate
    - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{
          [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
    }
    

    相关文章

      网友评论

          本文标题:TTTAttributedLabel 使用小记

          本文链接:https://www.haomeiwen.com/subject/awtllqtx.html