Search code examples
iosobjective-cuiviewuiimageviewcalayer

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


Solution

  • try using this it will work fine in my project

    self.view1.layer.cornerRadius=_slider1.value;//Value as per your requirement
    
    CALayer *borderLayer = [CALayer layer];
    CGRect borderFrame = CGRectInset(CGRectZero,-1,-1);
    [borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
    [borderLayer setFrame:borderFrame];
    [borderLayer setCornerRadius:_slider1.value];//Value as per your requirement
    [borderLayer setBorderWidth:_slider2.value];//Value as per your requirement
    [borderLayer setBorderColor:[[UIColor whiteColor] CGColor]];
    [self.view1.layer addSublayer:borderLayer];
    
    self.view1.clipsToBounds=YES;