Wednesday, December 01, 2010

Alpha for CALayer

One of the purposes of this blog is for me to post information that might help other developers, where the info isn't easily found on the web.

Some of these things are silly, and probably obvious to most people. But in today's age of "Google first, ask questions later," it makes sense for me to collect these helpful hints online.

So here's today's tip of the day.

On iOS (and likely OS X -- I don't develop for that platform yet), let's say you've been used to working with UIView-derived objects like UIImageView and UILabel. Let's say you recently decided to change many of your objects to CALayers in order to optimize things a bit.

(I should take a quick time out here to note that in most cases, CALayers won't perform better than UIViews on iOS. But there are advantages, and CALayers are surprisingly easy to work with.)

Anyway, let's say you need to vary the opacity of this CALayer. On your UIView object, the property would be alpha. But on a CALayer object, the property is opacity. That's it. Simple. Profound. And surprisingly difficult to find when you've been programming all day.

3 comments:

Nikhil Aneja said...

Thanks a lot Buddy..Save ma almost a day....
:)

Regards
Nikhil Aneja

Some Bloke said...

Thank you!

vamitrou said...

thanks