CALayer:
The CALayer class
manages image-based content and allows you to perform animations on that content. Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer’s main job is to manage the visual content that you
provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size,
and transform) that is used to present that content onscreen. Modifying the properties of the layer is how you initiate animations on the layer’s content or geometry. A layer object encapsulates the duration and pacing of a layer and its animations by adopting
the CAMediaTiming protocol,
which defines the layer’s timing information.
#import "ViewController.h"
@interface ViewController ()
@end
//图层CALayer
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view = [[UIView alloc ] initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor = [UIColor redColor];
view.layer.cornerRadius = 15; //视图是附着在图层上显示的
view.layer.borderWidth = 10;
[self.view addSubview:view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}结果:
本文介绍了CALayer类的基本概念及使用方法,展示了如何通过修改图层属性实现视觉效果的变化,如圆角和边框等,并提供了简单的代码示例。
262

被折叠的 条评论
为什么被折叠?



