iOS: Watch out for shadows

Quick tip … when working with CALayer shadows, its useful to set shouldRasterize to YES - this helps with performance (along with setting the shadowPath). The problem is that it also rasterises everything else in the layer, including all the text - which then looks awful. There are a couple of options …

  1. set the rasterization scale (thus ensuring the rasterization is done at correct scale for the device - retina/non-retina):

    1
    
    layer.rasterizationScale = [[UIScreen mainScreen] scale]];
    
  2. or move the shadow into its own layer and adding that as a sublayer.

Both options work - it depends on what your specific use case is, as to which is going to be better for your app.

Comments

comments powered by Disqus
Copyright © 2013 - Brothers Bennett - Powered by Hexo
- Ported theme GreyShade -