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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM