Reputation: 6109
As far as I know we can use core graphic such as CGContextSetShadowWithColor
to draw a shadow. However, we can also use CALayer to show the shadow as well.
Question :
what are the differences between 2 of them. Are there any rules to determine when we use core graphic to draw a or when we use CALayer to do the job
Upvotes: 1
Views: 341
Reputation: 22559
I would have to say that using CoreAnimation
is always preferred over CoreGraphics
, since it's more high level, and abstracts the low-level details of drawing the shadow. (It may also allow apple to optimize the shadow drawing without hurting your code syntax).
However, there are times where you are overriding drawRect:
anyways, and you have very specific use for the shadow, not the whole view's layer. You might wanna use CoreGraphics
shadows here.
One last note, CoreAnimation
gradients are much faster when rendering, take my word for it. I used it on UITableViewCell
, and the scroll performance significantly increased, as opposed to using CoreGraphics
Gradients. That comes at a price, though. It's a bit worse-looking.
Upvotes: 1