iOS开发中CALayer使用的基本教程

2020-01-14 17:52:10于丽

@end


复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置边框的宽度为20
    self.customView.layer.borderWidth=5;
    //设置边框的颜色
    self.customView.layer.borderColor=[UIColor blackColor].CGColor;
    
    //设置layer的圆角
    self.customView.layer.cornerRadius=20;
    
    //在view的图层上添加一个image,contents表示接受内容
    self.customView.layer.contents=(id)[UIImage imageNamed:@"me"].CGImage;
    
}
@end


 

iOS开发中CALayer使用的基本教程

说明:contents是id类型,可以接受内容,上面的实例让layer显示一张图片,仔细观察可以发现四个圆角的部分露了一个角出来。

产生的原因说明:

iOS开发中CALayer使用的基本教程

customview上的根layer

iOS开发中CALayer使用的基本教程

UIimage的图层

iOS开发中CALayer使用的基本教程