O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide by Joe Conway, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Layer Content

A layer contains a bitmap called its contents, which 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:

 ​ ​ ​ ​ ​ ​ ​ ​[​b​o​x​L​a​y​e​r​ ​s​e​t​B​a​c​k​g​r​o​u​n​d​C​o​l​o​r​:​c​g​R​e​d​d​i​s​h​]​;​

 ​ ​ ​ ​ ​ ​ ​ ​/​/​ ​C​r​e​a​t​e​ ​a​ ​U​I​I​m​a​g​e​ ​ ​ ​ ​ ​ ​ ​ ​U​I​I​m​a​g​e​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required