UIButton backgroundImage not getting trait collection set when switching to Dark Mode?

I have an existing app with a number of buttons whose width is determined by their text content. Since I don't know the width until runtime, the button's background is configured with a stretchable image so that the width (or height) can vary. After confuguring the Asset catalog to add a Dark appearance, I've noticed some curious behavior when toggling between light and dark mode and viewing these buttons.


When I toggle from light to dark mode and then resume my app, the visual appearance of the buttons does not change. If I print the debug description of the button's trait collection, the UserInterfaceStyle is Dark, as expected. But when I retrieve the background image using the button's backgroundImage(for:) method, it's trait collection's UserInterfaceStyle is still Light.


As a workaround - If I go into the Asset Catalog and change Slicing to none, so that the image is no longer stretchable, at runtime the button's visual appearance changes when toggling between Light and Dark Mode as expected. But, if I print the debug descriptions as described above, there still is a descrepancy between the Button and the background image.


Is there any additional configuration I need to do to get buttons with stretchable backgrounds to render correctly in both light and dark mode?


Feedback Assistant report is FB6626669