Bhavin Chauhan Bhavin Chauhan - 2 months ago 23
Objective-C Question

View Corner Radius Issue

i have one

UIView
and in that
UIView
i have
UIImageView
& what i have done is set
cornerRadius
to that
UIView
and also set
borderWidth
but i get nearly about 1 pixel space after that
UIView
so how can i fix that issue?

view1.clipsToBounds = YES;
view1.layer.cornerRadius = 150;
view1.layer.masksToBounds = YES;
view1.layer.borderColor = [UIColor whiteColor].CGColor;
view1.layer.borderWidth = 50;
view1.layer.opaque = NO;


You can check below image that show 1 pixel spacing.

Here is Demo Project Please Check That To - Click Here

Here how my view look like
enter image description here

Here is what i want
enter image description here

Properties

enter image description here

Answer

try using this it will work fine in my project

self.view1.layer.cornerRadius=_slider1.value;

CALayer *borderLayer = [CALayer layer];
CGRect borderFrame = CGRectMake(-1, -1, 302, 302);
[borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
[borderLayer setFrame:borderFrame];
[borderLayer setCornerRadius:_slider1.value];
[borderLayer setBorderWidth:_slider2.value];
[borderLayer setBorderColor:[[UIColor whiteColor] CGColor]];
[self.view1.layer addSublayer:borderLayer];

self.view1.clipsToBounds=YES;