1、知识点梳理
+1. 添加图层:
- 例如:在View上添加新图层
[self.view.layer addSublayer:layer];
- 2.设置图层的内容, layer的属性contents -> id类型,要强转
- 设置新图层的内容为一种图片
layer.contents = (id)[UIImage imageNamed:@"阿狸头像"].CGImage;
```
2、实例:在控制器的View上添加一个新的图层
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 创建图层
CALayer *layer = [CALayer layer];
layer.backgroundColor = [UIColor redColor].CGColor;
layer.frame = CGRectMake(0, 0, 100, 100);
layer.contents = (id)[UIImage imageNamed:@"阿狸头像"].CGImage;
[self.view.layer addSublayer:layer];
}