Search code examples
iosswiftuibuttonaccessibilitydynamic-type-feature

Can UIButton background image support Dynamic Type?


After watching this talk I would like to support Dynamic Type in my app. It's easy for labels, but what about UIButton with an image set as a background? Image is in pdf, single scale and Preserve Vector Data. UIButton has Accessibility > Adjusts Image Size checkmark on but still it doesn't work. I haven't set any constraint for size for that button.


Solution

  • The background image is scaled to fill the bounds of a UIButton.

    The only way to enlarge this kind of image is by using the Dynamic Type and change the size as you noticed in the WWDC video you watched.

    However, it's still possible to scale the image (not the background) and the font of your button using the text styles :

    myButton.titleLabel?.adjustsFontForContentSizeCategory = true
    myButton.adjustsImageSizeForAccessibilityContentSizeCategory = true
    

    Finally, the background image only adjusts its size to the bounds of its button according to the accessibility Dynamic Type sizes used for its title label.

    Besides, if you can't use the Dynamic Type in this case, you could take a look at the Large Content Viewer if need be ⟹ the UILargeContentViewerItem protocol is an iOS 13 new feature that shows the same HUD that's shown for standard bar items.