wreckingcode wreckingcode - 2 years ago 157
iOS Question

Circular UIImageView in UITableView without performance hit?

I have a

on each of my
cells, that display a remote image (using
). I've done some
layer styling to the image view, as such:

UIImageView *itemImageView = (UIImageView *)[cell viewWithTag:100];
itemImageView.layer.borderWidth = 1.0f;
itemImageView.layer.borderColor = [UIColor concreteColor].CGColor;
itemImageView.layer.masksToBounds = NO;
itemImageView.clipsToBounds = YES;

So now I have a 50x50 square with a faint grey border, but I'd like to make it circular instead of squared. The app
uses circular images in table views, and that's the effect I'd like to achieve. However, I don't want to use
, as that degrades my scrolling FPS.

showing circular

enter image description here

Is there any way to get this effect? Thanks.

Answer Source

Simply set the cornerRadius to half of the width or height (assuming your object's view is square).

For example, if your object's view's width and height are both 50:

itemImageView.layer.cornerRadius = 25;

Update - As user atulkhatri points out, it won't work if you don't add:

itemImageView.layer.masksToBounds = YES;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download