Code Snippet: Adding a UIImage into a CALayer
As a example, by adding the code below into your viewDidLoad method a CALayer called backgroundImage will be displayed. This CALayer also takes on the contents UIImage named fixedBackgroundImage.
UIImage *backgroundImageSource = [UIImage imageNamed:@"fixedBackgroundImage"]; CALayer *backgroundImage = [CALayer layer]; backgroundImage.zPosition = 0; [backgroundImage setFrame:CGRectMake(0, 0, 1024, 768)]; backgroundImage.contents = (id) backgroundImageSource.CGImage; [self.view.layer addSublayer:backgroundImage];
Note: This code is built to fit an iPad screen. Take a look at the '1024, 768' values if you would like to change the width and height of this CALayer.











