0

im trying to make a circle imageprofile, like the profile image of instagram/whatsapp. Right now my code seems to work, but i did it in 2 different ways and both works, so i want to know which one is the best

First way:

profileImageView.layer.cornerRadius = profileImageView.frame.width / 2
profileImageView.clipsToBounds = true

Second way

profileImageView.layer.cornerRadius = profileImageView.frame.width / 2
profileImageView.layer.masksToBounds = true

Also i would like if someone can explain me about "clipToBounds" and "maskToBounds", what they do. Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SXVBAKA
  • 3
  • 2
  • 1
    You can check about `clipsToBounds` and `masksToBounds` : http://stackoverflow.com/questions/1177775/how-is-the-relation-between-uiviews-clipstobounds-and-calayers-maskstobounds – Ashish Kakkad Aug 05 '15 at 04:34

2 Answers2

0

The way that I always do it, specifically in a situation where I want to show a profile picture in my application, I use this code:

profileImage.layer.cornerRadius = self.profileImage.frame.size.width / 2;
profileImage.clipsToBounds = true;

This is what I would recommend to do!

Stefan DeClerck
  • 1,162
  • 2
  • 12
  • 22
  • OP Not asking for code. OP asking for which code is batter and why we have to use like this. OP already defined that code is working fine. – Ashish Kakkad Aug 05 '15 at 05:41
  • thanks, its good to know that other people use the same code to make circle images! thanks! – SXVBAKA Aug 07 '15 at 14:37
0

clipsToBounds is a boolean value that determines whether subviews are confined to the bounds of the view. Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO. Basically, this thing plays with the view's property.

Whereas masksToBounds is a boolean indicating whether sublayers are clipped to the layer’s bounds.And this thing plays with the layer of the view.

Vikas Dadheech
  • 1,672
  • 12
  • 23