GoGreen
GoGreen

Reputation: 2251

Setting Corner Radius on ImageView is imperfect in iPhone 6 and 6 Plus

I am using imageViews in my app to which I set cornerRadius to make them circular. All that works fine, but when I verify it in iPhone 6 and 6 Plus, some parts at the edge seem cut off, for eg. the top part in the image below:

enter image description here

Note that I haven't added 3x launch image, so the app is actually displayed as a scaled version of the original.
I am assuming this issue happens because of the scaling factor. i.e. the width I specify in code is not what I actually see in the device. Also, I assume this will be fixed if I use autoLayout.

Are my assumptions correct? If not, please provide an explanation and a solution for the same. Thanks :) !

EDIT1:

My imageView is of 35 x 35 size. I set the corner radius as follows:

[commentCell.profileImageView.layer setCornerRadius:17.5];
[commentCell.profileImageView.layer setMasksToBounds:YES];

EDIT2:

Floating points doesn't seem to be it, because I tried the same with frame size 36 x 36 and corner radius 18.

Upvotes: 0

Views: 370

Answers (2)

Andrea
Andrea

Reputation: 26385

It happened to me too, probably is due to float rounding.
You can try 2 things:

  • mask the image view layer with a CAShapeLayer
  • redraw the image in a circle

L

CAShapeLayer *circleClipLayer=[CAShapeLayer layer];
UIBezierPath * circlePath = [UIBezierPath bezierPath];
[circlePath addArcWithCenter:yourcenter radius:yourradius startAngle:0 endAngle:2 * M_PI clockwise:YES];
circleClipLayer.path = circlePath.CGPath;
yourimageview.layer.mask=circleClipLayer;

Upvotes: 1

Munahil
Munahil

Reputation: 2419

Your assumptions are correct, however there is another solution too :

[commentCell.profileImageView.layer setCornerRadius:profileImageView.frame.size.width/2];

Upvotes: 1

Related Questions