masksToBounds vs clipsToBounds

What is the difference between clipsToBounds on UIView, and masksToBounds on it’s corresponding CALayer? Is there any?

When debugging I see that setting clipsToBounds = true on a UIView, automatically sets masksToBounds = true on the underlying CALayer, and vice versa.

From my understanding, UIViews are basically lightweight wrappers around CALayer, so it would make sense that clipsToBounds calls masksToBounds behind the scenes.

Is that assumption correct?

Answered by in 763070022

Yes, in general UIKit covers a lot of CALayer properties like this, although not always in a "light weight" manner (but that usually means there are very good reason to use the UIKit API over the CALayer API if you have a UIView).

As such we generally recommend that where there is an equivalent UIView and CALayer method for doing something, you should use the UIView method.

Accepted Answer

Yes, in general UIKit covers a lot of CALayer properties like this, although not always in a "light weight" manner (but that usually means there are very good reason to use the UIKit API over the CALayer API if you have a UIView).

As such we generally recommend that where there is an equivalent UIView and CALayer method for doing something, you should use the UIView method.

masksToBounds vs clipsToBounds
 
 
Q