码迷,mamicode.com
首页 > 其他好文 > 详细

用CATextLayer来实现一个UILabel

时间:2015-01-04 23:08:55      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:ios   uilabel   

用CATextLayer来实现一个UILabel

by 伍雪颖

技术分享

    CATextLayer *textLayer = [CATextLayerlayer];
    textLayer.frame =CGRectMake(100,100,100,100);
    [
self.view.layeraddSublayer:textLayer];
   
    textLayer.
foregroundColor = [UIColorblackColor].CGColor;
    textLayer.
alignmentMode =kCAAlignmentJustified;
    textLayer.
wrapped =YES;
   
   
UIFont *font = [UIFontsystemFontOfSize:15];
   
   
CFStringRef fontName = (__bridgeCFStringRef)font.fontName;
   
CGFontRef fontRef =CGFontCreateWithFontName(fontName);
    textLayer.
font = fontRef;
    textLayer.
fontSize = font.pointSize;
   
CGFontRelease(fontRef);
   
   
NSString *text =@"Cupid laid by his brand, and fell asleep";
   
    textLayer.string = text;

    textLayer.contentsScale = [UIScreen mainScreen].scale; // Retina显示

用CATextLayer来实现一个UILabel

标签:ios   uilabel   

原文地址:http://blog.csdn.net/rainlesvio/article/details/42401149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!