Layer Content

A layer is simply a bitmap, and its contents can be set programmatically or with an image. To set the contents programmatically, you either subclass CALayer or assign a delegate to an instance of CALayer. The delegate then implements drawing routines. (This is how implicit layers work; the view is its layer’s delegate.)

We will discuss drawing to a layer programmatically at the end of this chapter. For now, you’re going to set the contents of the layer using an image file.

In HypnosisView.m, add the following code to the initWithFrame: method:

-​ ​(​i​d​)​i​n​i​t​W​i​t​h​F​r​a​m​e​:​(​C​G​R​e​c​t​)​r​ {​ ​ ​ ​ ​s​e​l​f​ ​=​ ​[​s​u​p​e​r​ ​i​n​i​t​W​i​t​h​F​r​a​m​e​:​r​]​;​ ​ ​ ​ ​i​f​ ​(​s​e​l​f​)​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​s​t​r​i​p​e​C​o​l​o​r​ ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.