user7705612
user7705612

Reputation:

Swift & XCode - How to modify buttons width

Recently, I have needed to split this button so that they are constrained with the same height but different widths, split 60 - 40, along the screen. They also have to respond to any Iphone / Ipad screen. I currently have them set within a stack view so that they are positioned correctly yet this is not optimal and do not allow me to modify their width.

Is there a XCode creator solution? If not, is there a solution in code?

Images:

Goal: enter image description here

Current Hierarchy:
enter image description here

Upvotes: 0

Views: 372

Answers (1)

DonMag
DonMag

Reputation: 77423

You can use Proportional Widths.

  1. Set the constraints on your stack view so it is positioned and sized where you want it.
  2. Ctrl-Click-Drag from the Clear button to the Start button and select Equal Widths
  3. Edit the resulting constraint and set the Multiplier to 40:60 (for clarity... it could just as well be 4:6: or 2:3). The Equal Width label on the constraint will change to Proportional Width
  4. Set the Stack View to Alignment: Fill / Distribution: Fill / Spacing: (however much you want)

That should do it :)

Upvotes: 0

Related Questions