Need assistance setting two buttons of equal width, side by side Autolayout
you can done it using equal width to 2nd button like this
and the output is
Here is apple guide
iOS Autolayout: two buttons of equal width, side by side
Add the following constraints
- Assign equal width from button1 to button2.
- Assign horizontal spacing between both buttons.
- Assign leading space from button1 to its superview.
- Assign trailing space from button2 to its superview.
- Assign top space to both the buttons.
Let me know if it works for you.
Can't get auto layout to make two buttons side by side stay there
Insert those buttons into horizontal StackView component (which is available in iOS 9 and later) and set alignment to fill. Setup their constraints to have aspect ration on themselves and setup them to have equal width (at least that)... Much simpler approach IMO
see:
https://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views
How to add constraints to the following two buttons
Ctrl + Drag from one button to the other and add the Equal Width constraint.
Autolayout : Align two button side by side and move to right side when there is no image
Using two different buttons inside UIStackView will be very easy & effective:
Add constraints to side by side buttons
Just give constraint as in my image
First give constraint to textfield then Select both button and give constraints like in image and be sure that both buttons width and height is same
It should look like this
Autolayout with equal width and setting priority
iOS9 only apps:
This might be a good time to use the new Horizontal Stack View
. Just set distribution
to fill equally
and alignment
to fill
For iOS8 support:
You'll have to set the width constraint to equal width
between the components and the horizontal spacing
to 0
Set button1 to equal width with button2 then button1 to equal width with button3. This should be enough.
Arrange 3 UIButtons(of equal width) side-by-side
There are 2 ways to do this.
Way 1:
With use of equal width constraint of button
Select all 3 buttons and add
top, left , right, height and equal width
Way 2:
With use of Stack view
Step 1: Add 3 buttons.
Step 2: Select all that buttons, Once you selected, click on the Stack button in the Auto Layout toolbar at the bottom right of the storyboard canvas. see below in image.
Alternatively you can embed in From Editor -> Embed in -> StackView
Step 3:
Add Constraints to StackView. like below.
Step 4:
Select StackView, Once selected go to Attributes inspector. Change the Distribution to Fill Equally:
And its Done!
Related Topics
Logging Data on Device and Retrieving the Log
Best Way to Cache Images on iOS App
Failed to Read Values in Cfprefsplistsource iOS 10
Programmatically Change Rootviewcontroller of Storyboard
iOS Multiple Columns in Uitableview
How to Add Unique Constraints for Some Fields in Core Data
Simulate Force Touch/3D Touch on iPhone 6S or iPhone 6S Plus Simulators
How to Release a Cgimageref in iOS
How to Set Cg_Context_Show_Backtrace Environmental Variable
How to Add Minutes to Current Time in Swift
Generate a Random Float Between 0 and 1
Ios: Sample Code for Simultaneous Record and Playback
Adding Thousand Separator to Int in Swift