YYLabel 简单的使用

Podfile 中导入pod 'YYText'

 

头文件的引入#import <YYText/YYText.h>

 

添加依赖  CortText     QuartzCore     

使用:

NSString *showString = @"每个人都有两个我,一个在黑暗中醒着,一个在光明中睡着";
    
    YYLabel *textL = [[YYLabel alloc] initWithFrame:CGRectMake(50, 300, 300, 50)];
    textL.numberOfLines = 0;
    [self.view addSubview:textL];
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:showString];
    
    // 设置不同字体颜色
    [attString yy_setColor:[UIColor redColor] range:NSMakeRange(5, 2)];
    [attString yy_setColor:[UIColor redColor] range:[[attString string] rangeOfString:@"黑暗"]];
    
    //  设置不同字体大小
    [attString yy_setFont:[UIFont systemFontOfSize:17] range:attString.yy_rangeOfAll];
    [attString yy_setFont:[UIFont systemFontOfSize:30] range:NSMakeRange(12, 2)];
    
    textL.attributedText = attString;

 

posted @ 2019-12-31 14:46  走路蹩脚的火星人  阅读(2356)  评论(0编辑  收藏  举报