7

I am using an AQGridView to display my data in a grid on iPad. Every cell is a UIView subclass and typically, there are 18 cells displayed simultaneously.

I would like to add a round corner to these cells, so I set the cornerRadius property of the relevant layers (i.e. the layer of the main UIView and of one subview). However, this results in performance issues and the scrolling is not smooth any more. When using other CALayer properties, such as shadowOpacity, this does not happen.

Are there any other ways to add a rounded corner (apart from using an image)? Or am I doing something wrong?

fabian789
  • 8,348
  • 4
  • 45
  • 91

2 Answers2

28

I also saw a major performance hit when using cornerRadius on the layer of a view that contained a UIImageView subview. Rasterization solved that problem: view.layer.shouldRasterize = YES;

James Wald
  • 13,626
  • 5
  • 52
  • 63
  • 2
    you literally saved me tons of my time! :) – joe kirk Dec 15 '11 at 07:23
  • I have used this before with great success. However, rounding the corners on entire view causes some degradation in quality of the entire view: https://skitch.com/franklinwebber/8q8c2/ios-simulator – burtlo Mar 29 '12 at 19:21
  • 19
    However, I found that the issue was the rasterization was being performed at too low of a resolution and this solved the issue `myView.layer.rasterizationScale = [[UIScreen mainScreen] scale];` – burtlo Mar 29 '12 at 19:28
  • @james Wald . i had resoled the perfomence issue using "[myview.layer setShadowPath:[UIBezierPath bezierPathWithRect:myview.bounds].CGPath];". Shadow and corner radious is working fine in Portrait mode with smooth scrolling. but my app is supported in both mode and when i change the orientation shadow not working properly(shadow display according to fram of Portrait View) .so any idea how to resolved this ? – Hitarth Feb 16 '13 at 07:03
  • @Coder Perhaps you aren't setting the shadow path after the orientation change? The the view's bounds are probably changed according to the device orientation. You would have to set the shadow path again using the view's newly updated bounds. – James Wald Feb 19 '13 at 16:29
  • @JamesWald yes exactly . i am done with this. look into it http://stackoverflow.com/a/14910451/935381 Thanks. – Hitarth Feb 20 '13 at 04:57
0

It could be where you're placing the setCornerRadius call. Make sure it's somewhere that only gets called once, not, for example, in a drawRect method.

picciano
  • 22,341
  • 9
  • 69
  • 82