contentEdgeInsets
was deprecated in iOS 15, now I am using self.configuration.contentInsets
to set the padding of the button. But after I finished setting the configuration, I still need to call self.configuration.contentInsets.top/bottom/leading/trailing
to calculate the intrinsicContentSize
, but it is always return 0
. The self.contentEdgeInsets.left/right/top/bottom
works fine, but I do not want to use it since it is already deprecated, is there other solution?
CodePudding user response:
now I am using
self.configuration.contentInsets
to set the padding of the button.
You cannot alter the configuration through the property value (a pointer) which a UIButton
already holds. Instead you should trigger a setter method, by settings configuration
property as a whole:
UIButtonConfiguration *config = _mButton.configuration;
config.contentInsets = NSDirectionalEdgeInsetsMake(10, 10, 10, 10);
_mButton.configuration = config;