Reputation: 2251
I am using imageView
s 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:
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
Reputation: 26385
It happened to me too, probably is due to float rounding.
You can try 2 things:
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
Reputation: 2419
Your assumptions are correct, however there is another solution too :
[commentCell.profileImageView.layer setCornerRadius:profileImageView.frame.size.width/2];
Upvotes: 1