CATextLayer的学习

@interface CATextLayer : CALayer

{

@private

  struct CATextLayerPrivate *_state;

}

//需要呈现的文本,可以是NSString和NSAttributedString,默认情况下为nil

@property(copy) id string;


//使用的字体,可以是CTFontRef, CGFontRef或者是一个font的名字,默认为Helvetica font,当且仅当stringNSAttributedString时使用

@property CFTypeRef font;


//字体的大小,默认为36,当且仅当string不为NSAttributedString或者Animatable时使用

@property CGFloat fontSize;


//用来绘制text的颜色,默认为不透明白色,当且仅当string不为NSAttributedString和Animatable时使用

@property CGColorRef foregroundColor;


//默认为NO,若为YES表示可自适应layer的bounds

@property(getter=isWrapped) BOOL wrapped;


//描述string如何在层内实现截断自适应bounds,可以为‘none’,‘start’,以及‘end’,默认情况下为'none‘

@property(copy) NSString *truncationMode;


//描述各个行间对齐的方式,可以为‘natural','left','right','center',以及'natural',默认为'natural'

@property(copy) NSString *alignmentMode;


@end



简单的实例:

CATextLayer *textLayer = [CATextLayer layer];

    [textLayer setFrame:CGRectMake(10, 100, 300, 50)];

    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:@"CATextLayer测试学习" attributes:@{NSForegroundColorAttributeName :[UIColor redColor]}];

    [attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, 11)];

    [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(11, 4)];

    [textLayer setString:attributeString];

    [textLayer setAlignmentMode:@"center"];//设置文本对齐方式

    [textLayer setFontSize:13];//此方法在此无效,因为stringNSMutableAttributedString

    [self.view.layer addSublayer:textLayer];


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值