UIButton image not honoring dynamic type changes

I am unable to get a UIButton's image to size as I change the font size. I can get the text in the label to work correctly using the adjustsFontForContentSizeCategory property on the button's label, but there appears to be now equivalent for the image.

If I restart the app after making the font size change, the button does indeed scale the image correctly so I know I have the preferred configuration setup correctly.

I figured I could work around the issue using traitCollectionDidChange and comparing the preferredContentSizeCategory, but I am still unable to get the button to resize itself no matter what I attempt to tweak.

Anybody else running into this issue? Any workarounds?
Post not yet marked as solved Up vote post of hotngui Down vote post of hotngui
988 views

Replies

I was able to get my image in the UIButton to size with the dynamic type changes by utilizing UIImage.SymbolConfiguration.init(font: font)

For example - I am using SF Symbol image "checkmark.square.fill" for my Button's image.

For it to resize - you need a SymbolConfiguration - I used the init(font:...) set up.

let config = UIImage.SymbolConfiguration.init(font: UIFont.preferredFont(forTextStyle: .footnote))
let checkbox = UIImage(systemName: "checkmark.square.fill", withConfiguration: config)
myButton.setImage(checkbox, for: .selected)
myButton.adjustsImageSizeForAccessibilityContentSizeCategory = true

Thanks. I can't remember the details but I did eventually figure it out. My original post is 3 years old and I have not figured out how to delete/close a post.