changing property contentsGravity in transform-only layer, will have no effect changing property contentsGravity in transform-only layer, will have no effect ios ios

changing property contentsGravity in transform-only layer, will have no effect


It could happen because you changed the Mode attribute of the StackView:

enter image description here

I got this warning when I set Mode to Aspect Fit.


Any layer change on a UIStackView will result in this warning. As the warning points out UIStackView is a transform-only layer and it differs quite slightly from a UIView. As per documentation:

The UIStackView is a nonrendering subclass of UIView; that is, it does not provide any user interface of its own. Instead, it just manages the position and size of its arranged views. As a result, some properties (like backgroundColor) have no effect on the stack view. Similarly, you cannot override layerClass, drawRect:, or drawLayer:inContext:.

More on this here.

It may not point to the exact source of the OP's issue but hopefully, it will shed some light on why UIStackView behaviour is not the same and should not be confused with UIView.


For someone that need: I set clipToBounds to false in StackView.