iOS Creating a CALayer


Example

You can create a CALayer and set its frame like this:

Swift:

let layer = CALayer()
layer.frame = CGRect(x: 0, y: 0, width: 60, height: 80)

Objective-C:

CALayer *layer = [[CALayer alloc] init];
layer.frame = CGRectMake(0, 0, 60, 80);

You can then add it as a sublayer to an existing CALayer:

Swift:

existingLayer.addSublayer(layer)

Objective-C:

[existingLayer addSublayer:layer];

Note:

To do this you need to include the QuartzCore framework.

Swift:

 @import QuartzCore

Objective-C

#import <QuartzCore/QuartzCore.h>