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.

Accepted Reply

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.

Replies

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

  • I'm pretty sure that button configuration buttons will always use the image's native size, while non-configuration buttons will size to fit the layout. In some ways not providing good control over this was oversight, but at the same time its likely better for clients to have assets that are the size they want them to be instead of oversized assets that are resized to fit at display time.

Add a Comment

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.

  • Hi @ortwin what did apple anwser to your feedback? weird thin is that in documentation apple says "effect of these properties can be replicated via UIButtonConfiguration.contentInset" but is not true =/

Add a Comment