Using UIButtonConfiguration, what is the equivalent to using UIButton.imageEdgeInsets

I can't seem to find the equivalent. I don't think imagePadding is the right UIButtonConfiguration property. What would be the appropriate refactor the header comments just say this

// The effect of these properties can be replicated via UIButtonConfiguration.contentInset and UIButtonConfiguration.imageToTitlePadding. They are ignored when a configuration is set.
@property(nonatomic) UIEdgeInsets contentEdgeInsets API_DEPRECATED("This property is ignored when using UIButtonConfiguration", ios(2.0,15.0), tvos(2.0,15.0)) UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero. On tvOS 10 or later, default is nonzero except for custom buttons.
@property(nonatomic) UIEdgeInsets titleEdgeInsets API_DEPRECATED("This property is ignored when using UIButtonConfiguration", ios(2.0,15.0), tvos(2.0,15.0));                // default is UIEdgeInsetsZero
@property(nonatomic) UIEdgeInsets imageEdgeInsets API_DEPRECATED("This property is ignored when using UIButtonConfiguration", ios(2.0,15.0), tvos(2.0,15.0));                // default is UIEdgeInsetsZero

And I don't see imageToTitlePadding on Apple's public documentation so I'm not sure how to use it.

Answered by Frameworks Engineer in 753592022

There isn't a direct conversion, but the UIButtonConfiguration.contentInset always applies (its an inset from the button bounds to any content at all). UIButtonConfiguration.imagePadding applies if there is text & image and not otherwise (looks like the comment in the header wasn't fixed when that property got renamed!)

If you have an image-only button, you probably just want contentInset.

Accepted Answer

There isn't a direct conversion, but the UIButtonConfiguration.contentInset always applies (its an inset from the button bounds to any content at all). UIButtonConfiguration.imagePadding applies if there is text & image and not otherwise (looks like the comment in the header wasn't fixed when that property got renamed!)

If you have an image-only button, you probably just want contentInset.

Thanks for answering! I have another question, In this code https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/ui/autofill/form_input_accessory/branding_view_controller.mm;l=141?q=branding_view_controller, the image associated (the first logo above the keyboard) looks bigger. Would you happen to know possible reasons why the scaling would be different? I already checked the image scale and size and found that they were 3 and 24x24 respectively. So not sure why when using UIButtonConfiguration the scale looks like 3 but without UIButtonConfiguration the scale looks like 2 but says 3.

Image of the comment above

Nevermind, I was told that the screenshot on the left is intended. Thanks! Marking resolved.

@Rincewind I do think this is a serious oversight. Particularly with assets preserving vector data, we really should have fine-grained control over the button image size, irrespective of the image's native size. Imo, UIButton.Configuration.contentsInsets doesn't behave as advertised. It's defined as the distance from the button's content area to its bounds. So the image should be resized to fit in the content area.

I've logged FB12471726.

Using UIButtonConfiguration, what is the equivalent to using UIButton.imageEdgeInsets
 
 
Q