0

We create a UIButton by initialising it with a configuration and embedding it within a (horizontal) UIStackView. We set setContentHuggingPriority to required because we want the button to only take up as much space as it actually needs.

    var configuration = UIButton.Configuration.filled()
    configuration.title = "Send to"
    configuration.baseBackgroundColor = .red

    let customButton = UIButton(configuration: configuration)
    customButton.setContentHuggingPriority(.required, for: .horizontal)

When running attached to the debugger, it looks like this:

what it should look like

When we open the app manually by tapping on the icon, i.e. not connected to the debugger, it looks like this:

what it looks like

When I attach the debugger after I launched the app manually and inspect the view hierarchy I see that the intrinsic content size width is 59 instead of 83 (when attached to debugger).

It seems that the intrinsic content size is wrong, but why? Is it a bug at Apple? What could be wrong?

2
  • Thanks for your reply, same result sadly enough Commented May 28 at 14:58
  • Turns out there was nothing wrong with this code. After a long search I found an evil UIButton extension in our project which messed up the intrinsicContentSize (created by previous code owners). Commented May 29 at 12:05

1 Answer 1

0

Turns out there was nothing wrong with this code. After a long search I found an evil UIButton extension in our project which messed up the intrinsicContentSize (created by previous code owners).

Not the answer you're looking for? Browse other questions tagged or ask your own question.