0

I intend to use the following lines of code to add a "round view":

_myBackView = [[UIView alloc] initWithFrame:rect];
_myBackView.backgroundColor = [UIColor colorWithR:153 G:85 B:57 alpha:1.0];
_myBackView.layer.cornerRadius = artworkViewWidth / 2;
_myBackView.layer.masksToBounds = YES;
_myBackView.layer.borderWidth = 0;
_myBackView.clipsToBounds = NO;
[self.view addSubview:_myBackView];

The view is created fine and seems mostly round. But the problem is it does not seems to be "100% round" - the four edges seems to be a bit clipped still, although I had the clipsToBounds property set to NO.

Any guidance will be appreciated.

EDIT: just added the repro picture. Please pay attention to the 4 edges which were clipped. repro picture

Jack X.
  • 85
  • 2
  • 10
  • Would help to have the image you are testing with. Also, is the image a square? – CodeBender Jul 01 '16 at 03:04
  • Please include the computation for `rect`. That rect must have `width==artworkViewWidth` for the corner radius to be correct. If it does, the view will form a perfect circle. – danh Jul 01 '16 at 03:24
  • @CodeBender thanks for the response. I've included the screen shot. I'm not directly displaying an image here yet, but just testing the cornerRadius stuff with a UIView directly. – Jack X. Jul 01 '16 at 03:29

2 Answers2

0

You can try this (use a circle png mask layer)

- (void)useMaskFor: (UIView*)colorArea {

    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame = colorArea.bounds;
    UIImage *maskImage = [UIImage imageNamed:@"cirMask.png"];
    maskLayer.contents = (__bridge id)maskImage.CGImage;
    colorArea.layer.mask = maskLayer;
}

Answered from this How to draw a custom UIView that is just a circle - iPhone app

Community
  • 1
  • 1
Proton
  • 1,335
  • 1
  • 10
  • 16
0
 _image.layer.cornerRadius = _image.frame.size.height/2;

 _image.layer.masksToBounds = YES;

try the code above.

Cihan Tek
  • 5,349
  • 3
  • 22
  • 29
remyr3my
  • 768
  • 1
  • 6
  • 19