Reputation: 1039
I want the same space between my six buttons shows in the picture, I'm having problems with autolyout, do you know how can I put them with the same equal spacing? all of them have the same dimension, widht and height: 36
They are in an UIView and the UIView is inside UITableViewController like you can see in the picture
Upvotes: 0
Views: 139
Reputation: 130
use UICollectionView, and maintain cell spacing correctly...set horizontal scroll only.It looks perfectly, but it consumes extra memory..
Upvotes: 0
Reputation: 146
As all the icons are of same size, you can manage this through code which is generic to all device resolutions. A small calculation would help.
In this case,
let x = screenwidth (or UIView)
y = width of the icon (36 here)
a = space between superview and first icon (Leading Space)
b = space between last icon and super view (Trailing space)
First add width and height constraints to all the icons so that the width is constant.
Now add horizontal spacing constraints from 2nd button to 1st button (d), 3rd button button to 2nd button(d), 4th button to 3rd button(d) and so on till 6th button to 5th button(d) and give these constraints.constants the below value programatically by creating nslayoutconstraint variables.
As the spacing should be same, all these spacing constraints will equal to on evalue, say d.
d + d + d + d + d = (x - 6y - a - b)
5d = (x - 6y - a - b)
d = (x - 6y - a - b)/5
Upvotes: 1
Reputation: 2162
There are two ways, 1. Insert views between the buttons, that should be proportional to the superview and keep the view widths same. 2. Add constraints for every button centre to superview centre and put the multipliers as to get the same distance from centre.
Upvotes: 0
Reputation: 1130
Because there is no another solution for set equal space between objects, so you need to create spaceView for that. Just follow that link and you will get what you want. I have personally tried that thing and it work for me. So try it.
If you have any doubt let me know I will explain it.
I hope it will help you!
Upvotes: -1
Reputation: 119031
Use a stack view if you can.
Otherwise place views in between each button and set them to have equal width to each other.
Upvotes: 1