当前位置: 移动技术网 > 移动技术>移动开发>Android > TYAttributedLabel的使用

TYAttributedLabel的使用

2020年07月17日  | 移动技术网移动技术  | 我要评论
//提示内容 lblContent=[[TYAttributedLabel alloc]init]; [bgView addSubview:lblContent]; lblContent.delegate=self; NSString *text = @" 温馨提示\n亲,感谢您对xxxx一直以来的信任!更新了xxxx《aaaa》和《bbbb》,特向您说明如下:\n1、为您xxxxxxxxxxxxx"; [lblContent setText:text.
#import "TYAttributedLabel.h"
 //提示内容
    lblContent=[[TYAttributedLabel   alloc]init];
    [bgView   addSubview:lblContent];
    lblContent.delegate=self;
    NSString *text = @"    温馨提示\n亲,感谢您对xxxx一直以来的信任!更新了xxxx《aaaa》和《bbbb》,特向您说明如下:\n1、为您xxxxxxxxxxxxx";
    [lblContent setText:text];
    // 文字间隙
    lblContent.characterSpacing = 2;
    // 文本行间隙
    lblContent.linesSpacing = 5;
    TYTextStorage  *  titleStorage = [[TYTextStorage alloc]init];
    titleStorage.range = [text rangeOfString:@"温馨提示"];
    titleStorage.textColor =[UIColor   hx_colorWithHexString:blackFontColor];
    titleStorage.font = [UIFont boldSystemFontOfSize:20];
    [lblContent addTextStorage:titleStorage];
    TYTextStorage  *  textStorage = [[TYTextStorage alloc]init];
    textStorage.range = [text rangeOfString:@"《aaaa》"];
    textStorage.textColor =[UIColor   hx_colorWithHexString:navBarColor];
    textStorage.font = [UIFont boldSystemFontOfSize:14];
    [lblContent addTextStorage:textStorage];
    TYTextStorage  *  privacyStorage = [[TYTextStorage alloc]init];
    privacyStorage.range = [text rangeOfString:@"《bbbb》"];
    privacyStorage.textColor =[UIColor   hx_colorWithHexString:navBarColor];
    privacyStorage.font = [UIFont boldSystemFontOfSize:14];
    [lblContent addTextStorage:privacyStorage];
     //添加超链接
    [lblContent   addLinkWithLinkData:@"aaaa" linkColor:[UIColor   hx_colorWithHexString:navBarColor] underLineStyle:kCTUnderlineStyleNone range:[text rangeOfString:@"《aaaa》"]];
    //添加超链接
    [lblContent   addLinkWithLinkData:@"bbbb" linkColor:[UIColor   hx_colorWithHexString:navBarColor] underLineStyle:kCTUnderlineStyleNone range:[text rangeOfString:@"《bbbb》"]];
    [lblContent sizeToFit];
    CGFloat   height_lblContent=[lblContent  getSizeWithWidth:gScreenWidth-20].height;
    [lblContent   mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(height_lblContent);
        make.bottom.mas_equalTo(-80);
        
    }];


添加协议

<TYAttributedLabelDelegate>

点击超链接

#pragma mark - Delegate
//TYAttributedLabelDelegate
- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageClicked:(id<TYTextStorageProtocol>)TextRun atPoint:(CGPoint)point {
    if ([TextRun isKindOfClass:[TYLinkTextStorage class]]) {
        NSString *linkStr = ((TYLinkTextStorage*)TextRun).linkData;
        if ([linkStr   isEqualToString:@"aaaa"]) {
            WYWebController *webVC = [WYWebController new];
            webVC.mTitle = @"aaaa";
            webVC.url =@"aaa";
            webVC.hidesBottomBarWhenPushed=YES;
            [self.nav pushViewController:webVC animated:YES];
        }else{
            
            WYWebController *webVC = [WYWebController new];
            webVC.mTitle = @"bbbb";
            webVC.url =@"bbbb"
            webVC.hidesBottomBarWhenPushed=YES;
            [self.nav pushViewController:webVC animated:YES];
            
        }
    }
}

本文地址:https://blog.csdn.net/weixin_43205520/article/details/107366075

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网