what is relation between masksToBounds and cornerRadius?
After providing cornerRadius
which specifies a radius used to draw the rounded corners of the receiver’s background.
Now it depends on masksToBounds
which determines if the sublayers are clipped to the receiver’s bounds. So if it is set to YES
, an implicit mask matching the layer bounds is applied to the layer, including the effects of the cornerRadius
property. If it is set to YES
and a mask property is specified, the two masks are multiplied to get the actual mask values.
For example:
If you set that on a CALayer
with image contents, the image will still be drawn outside the corner radius boundary. You can solve this by setting sublayer.masksToBounds
to YES
; but if you do that, the shadows won’t show up because they’ll be masked out!
eon
Updated on June 09, 2022Comments
-
eon almost 2 years
My scroll has some views that is
cornerRadius = 10.0
andmasksToBounds = YES
.This causes a performance issue for scrolling my scroll view. Though I tried each view's
shouldRasterize
is setYES
, the issue is not solved.However, I know the solution for this issue. That is what
masksToBound
is setNO
. (masksToBound's
default value is NO) AlthoughmasksToBound
isNO
, my views's corners still have curve and the performance issue is solved, too.I want to know about relation between
cornerRadius
andmasksToBounds
. I'm afraid of unexpected issues with this setting.Thank you.