Transparent Views

Chapter 7 introduced the UICompositeImageView class, which allowed multiple images to be layered on top of each other, adding layers of transparency to create overlays. The UIView class provides a similar function called setAlpha, allowing a view's transparency to be adjusted.

[ mainView setAlpha: 0.5 ];

This can be useful when superimposing multiple views, such as creating semi-transparent buttons and navigation bars, to allow text or images to remain visible through the object. The alpha value ranges from 0 to 1, where 0 makes a view totally invisible and 1 makes the view completely cover whatever is below.

To use this, create two views using overlapping frames. Set the alpha level of the front view using setAlpha. Now, add the first view followed by the second to your controlling view. The frontmost view should be semi-transparent.

Get iPhone Open Application Development 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.