美文网首页
iOS 富文本部分字段添加点击_phoneclone

iOS 富文本部分字段添加点击_phoneclone

作者: FengINC | 来源:发表于2021-08-24 10:04 被阅读0次

    UITextView*jladyisnseTextbutView = [[UITextViewalloc]initWithFrame:CGRectMake(30,TransHeight/4*3-50,TransWidth-60,80)];

        jladyisnseTextbutView.editable=NO;

        jladyisnseTextbutView.backgroundColor= [UIColorclearColor];

        jladyisnseTextbutView.delegate=self;

        jladyisnseTextbutView.textContainer.lineFragmentPadding = 0.0;

        jladyisnseTextbutView.textContainerInset=UIEdgeInsetsMake(15,0,0,0);

        //点击字体的颜色

        jladyisnseTextbutView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]};

        [self.viewaddSubview:jladyisnseTextbutView];

        //富文本添加

        NSString*fuwenyiseString =@"点击事项";

        NSString *resuitextTring = [NSString stringWithFormat:@"同意并接受我们的%@",fuwenyiseString];

        NSRangediaNbuttonRange = [resuitextTringrangeOfString:fuwenyiseString];

        // 字体的行间距

        NSMutableParagraphStyle *hangjuTextStyle = [[NSMutableParagraphStyle alloc] init];

        hangjuTextStyle.lineSpacing=4;

        //数组

        NSMutableAttributedString *fisymnaiNuttauBurString = [[NSMutableAttributedString alloc] initWithString:resuitextTring attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:15.0],NSForegroundColorAttributeName:[UIColor whiteColor],NSParagraphStyleAttributeName:hangjuTextStyle}];

        //可点击字体的范围设置

        [fisymnaiNuttauBurStringaddAttribute:NSLinkAttributeNamevalue:@"privacy://"range:diaNbuttonRange];

        jladyisnseTextbutView.attributedText= fisymnaiNuttauBurString;

    #pragma mark - UITextViewDelegate

    -(BOOL)textView:(UITextView*)textViewshouldInteractWithURL:(NSURL*)URLinRange:(NSRange)characterRange{

        if ([URL.scheme isEqualToString:@"privacy"]) {

        //点击需要跳转的页面

            returnNO;

        }

        return YES;

    }

    相关文章

      网友评论

          本文标题:iOS 富文本部分字段添加点击_phoneclone

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