重繪Label實現字體的各種變化 顏色 字體大小 下劃線

CATextLayer字體模糊問題

把其中的幾個字變深色一點或者變顏色,代碼如下:

NSMutableAttributedString *attriString = [[[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"Promotion", nil)]
                                                     autorelease];
           [attriString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor colorWithRed:255 green:200 blue:0 alpha:1].CGColor range:NSMakeRange(0,124)];
           [attriString addAttribute:(NSString *)kCTForegroundColorAttributeName
                               value:(id)[UIColor redColor].CGColor
                               range:NSMakeRange(124, 6)];
           [attriString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[UIColor colorWithRed:255 green:200 blue:0 alpha:1].CGColor range:NSMakeRange(130,10)];
           CATextLayer *textLayer = [CATextLayer layer];
           textLayer.string = attriString;
           textLayer.fontSize=15;
           textLayer.frame = CGRectMake(0, 20, 280, 160);

           textLayer.backgroundColor=[[UIColor clearColor]CGColor];

          //需要設置CALayercontentsScale屬性。這個值來自於屏幕的backingScaleFactor, contentsScale = 2表示retina屏幕;

               textLayer.contentsScale = 2;

           [whiteBackground.layer addSublayer:textLayer];




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章