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;
相關文章
相關標籤/搜索