美文网首页
富文本方式添加超链接效果

富文本方式添加超链接效果

作者: 不泯iOS | 来源:发表于2019-08-26 21:58 被阅读0次
    UITextView *tv = [[UITextView alloc]initWithFrame:CGRectZero];
    tv.delegate = self;
    tv.editable = NO;
    [self.view addSubview:tv];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:@"注册即代表您已阅读并同意《注册协议》" attributes:@{NSForegroundColorAttributeName:UIColor.darkGrayColor}];
    //给指定的部分添加链接
    [attr addAttribute:NSLinkAttributeName value:@"https://www.baidu" range:NSMakeRange(12, 6)];
    tv.attributedText = attr;
     //给链接部分更改自定义颜色
    tv.linkTextAttributes = @{NSForegroundColorAttributeName:Orange_color};
    [tv mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(view.mas_bottom).offset(10);
                    make.height.equalTo(@30);
                    make.left.equalTo(self.view.mas_left).offset(16);
                    make.right.equalTo(self.view.mas_right).offset(-16);
    }];
    

    相关文章

      网友评论

          本文标题:富文本方式添加超链接效果

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