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
I would have to say that using
CoreAnimationis always preferred overCoreGraphics, 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 useCoreGraphicsshadows here.One last note,
CoreAnimationgradients are much faster when rendering, take my word for it. I used it onUITableViewCell, and the scroll performance significantly increased, as opposed to usingCoreGraphicsGradients. That comes at a price, though. It’s a bit worse-looking.