How do I crop the edges of a picture to a circle?
First, the use of Cornerradius:
Select the image in Ib, and in the identity panel, press the + sign button under User Defined Runtime attributes to add the following key values:
Note that the value of Cornerradius is 20 because the size of the picture is 40,40/2=20.
Then in the Properties panel, tick clip subviews:
The picture in the storyboard doesn't change any more, but you can see the effect when you run the app:
Note that if the length of the ImageView is unequal, a rounded rectangle is obtained:
Second, the use of Cashapelayer
Draw an oval Calayer first, if the aspect ratio of the circle is 1 is the positive circle, otherwise is the ellipse:
Let group = CGRectMake (0,0,40,40)
Masklayer=cashapelayer ()
Let Maskpath = Uibezierpath (Ovalinrect:group)
Masklayer.fillcolor=uicolor.whitecolor (). Cgcolor
Masklayer.path = Maskpath.cgpath
Then apply this calayer as a mask to the ImageView:
ImageView.layer.mask = Masklayer
The results are similar to the above. The difference is that if the group has a wide range of lengths, it is possible to get an oval clipping effect instead of the rounded rectangle above.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Crop a picture to a rounded edge