CALayer渲染内容图层。与UIImageView相比,不具有事件响应功能,且UIImageView是管理内容。
注意事项:如何使用delegate对象执行代理方法进行绘制,切记需要将delegate设置为nil,否则会导致异常crash。
CALayer绘制图片与线条效果图:
代码示例:
CGPoint position = CGPointMake(160.0, 200.0);
CGRect bounds = CGRectMake(0.0, 0.0, 150.0, 150.0);
CGFloat cornerRadius = 150.0 / 2;
CGFloat borderWidth = 2.0;
// 阴影层
CALayer *layerShadow = [[CALayer alloc] init];
layerShadow.position = position;
layerShadow.bounds = bounds;
layerShadow.cornerRadius = cornerRadius;
layerShadow.bord