tags:

views:

27

answers:

1

At times i have seen people setting up layer properties for a view object like this:

[self.view.layer setBorderWidth:1.0f];
[self.view.layer setBorderColor:[UIColor colorWithRed:.486 green:.486 blue:.486 alpha:1.0f].CGColor];
[self.view.layer setShadowColor:[UIColor whiteColor].CGColor];

Can you please explain the importance of setting layer properties. Not able to understand what a layer is in a UIView...

A: 

It would take a book to explain every detail of layers, but essentially a layer can best be described as a 2D surface that can be manipulated in three dimensions. This 3D manipulation is what makes layers useful for fancy effects such as drop shadows, affine transforms, etc. Layers are fundamental to CoreAnimation - hence the "CA" in CALayer. Something like Apple's CoverFlow view would be achieved using layers.

On the iPhone (but not Mac OS X), every view has a layer (the term is "layer-backed view"). So the code you presented is simply setting properties on the view's layer. Essentially this is a cheap way of adding more effects, e.g. borders, rounded corners, to a UIView.

Echelon
Understood. Thanks a lot!!!
Abhinav