0

Referencing this answer, I'm trying to make a UIImageView display a circular image. I generated a mask and tried using that image to mask it but that didn't work either.

When I try to mask the image, or change the corners nothing happens. That's this: [proPic.layer setCornerRadius:proPic.frame.size.width/2];

When I call [proPic.layer setMasksToBounds:YES]; the image disappears completely. Same thing when I tried using a third party library to mask the image.

Any advice?

EDIT:

//Profile Picture
proPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"DummyProPic"]];
//Mask Profile Picture to be circular
[proPic.layer setCornerRadius:proPic.frame.size.width/2];
//With this line added, the picture disappears
//Without this line, nothing is done to mask the image
[proPic.layer setMasksToBounds:YES];

[self.contentView addSubview:proPic];
[proPic mas_makeConstraints:^(MASConstraintMaker *make) {

    make.top.equalTo(self.contentView.mas_top).with.offset(padding.top);
    make.centerX.equalTo(self.contentView.mas_centerX);
    make.height.equalTo(@120);
    make.width.equalTo(@120);
}];
Community
  • 1
  • 1
jboulter11
  • 152
  • 1
  • 2
  • 12

3 Answers3

0

You should remove the .layer for masking to bounds. Try:

[proPic setMasksToBounds:YES];
Stephen
  • 1,427
  • 1
  • 17
  • 42
0
[proPic.layer setCornerRadius:60];
[proPic.layer setMasksToBounds:YES];

This works, it doesn't like the proPic.frame.size.width/2 part.

jboulter11
  • 152
  • 1
  • 2
  • 12
0

If setMasksToBounds create problem then remove the masking and you can try with following

proPic.clipsToBounds=YES;

it may help you.

Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43