Mac Catalyst UIButton Configuration Issues?

66 Views Asked by At

I currently have my application set to run on iPad & Mac (Mac Catalyst), with my interface option set to Optimize for Mac, and am having serious difficulty updating the button padding when running on my Mac...


When I have Scaled to Match iPad selected, this is what it looks like:

enter image description here

When I have Optimize for Mac, it then becomes this...

enter image description here


Here is a quick snippet I put together to try isolating a solution. This exact snippet products the above images when toggling the Mac Catalyst Interface.

var config = button.configuration

config?.imagePadding = 20
config?.titlePadding = 20
config?.contentInsets = .init(top: 0, leading: 20, bottom: 0, trailing: 20)
button.configuration = config
button.setNeedsUpdateConfiguration()
button.updateConfiguration()
1

There are 1 best solutions below

2
HangarRash On

I made a quick test app and used the following button code:

var cfg = UIButton.Configuration.gray()
cfg.image = UIImage(systemName: "clock")
cfg.title = "Due Orders"
cfg.imagePadding = 20
cfg.contentInsets = .init(top: 20, leading: 20, bottom: 20, trailing: 20)
let button = UIButton(configuration: cfg, primaryAction: UIAction(handler: { action in
}))

This gives the following result when run on a Mac using "Scaled to Match iPad":

enter image description here

and the following when run on a Mac using "Optimize for Mac":

enter image description here

When optimized for Mac, the button ignores the content insets and the image padding leaving you with a standard Mac button look. But note that there is space between the image and the title.

Your code doesn't show all of your button setup so it isn't clear how you are getting no space between the image and title.