YYLabel 简单的使用

Podfile 中导入pod 'YYText'字体

 

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

 

添加依赖  CortText     QuartzCore     code

使用:blog

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;
相关文章
相关标签/搜索