I'm new to stackviews and have been trying to use it in a collectionViewCell. This works kind off however i would like to make spacing between the label and image and the two labels. Beside this i also want to make spacing between the label and the edges of the collectionViews. How can i achieve this? here is some images of my stackviews
i would like to make spacing between the label and image and the two labels
Select the vertical stack view right beneath ItemCell, then go to the attributes inspector and change the spacing value, as shown below.
Beside this i also want to make spacing between the label and the edges of the collectionViews.
You have to use constraints to achieve this.
Related
How do I adjust the TextField inside my StackView to fill in the gap between it and the label that I also have placed in there? I'm using the Storyboard.
Currently looks like this:
Desired look:
Thank you.
This is achievable by just using nested UIStackView.
Add a Horizontal UIStackView first with spacing as 15 and distribution and alignment as Fill.
Inside it add two vertical UIStackView with both set to fill equally as the distribution and alignment as Fill. The spacing can be set to 10.
Inside the first vertical one add two UILabel and inside the second one add two UITextField.
And this will result in:
The labels will expand to fit the largest label.
I have a Horizontal UIStackView with two UILabels. I need it to be styled like UITableViewCellRightDetail.
The first Label (on the left) should have more priority in resizing.
Here is the example:
I need it to be like this:
You can just use right alignement for the second label to achieve the desired appearance on your second image.
However this will not affect size of the labels. If you want first label to fit as much as it can, you can define a width constraint and set it manually from code after you calculate it. The second label will just have leading and trailing constraints.
How would I go about creating a layout like this using autolayout?
The icon is UIImage, text is UILabel.
The label text can vary in width, but will always be single-line. How do I force the label to scale with the text horizontally and UIImage to be immediately to the left of the label?
I have tried using attributedText. I also tried views as containers and a horizontal stack view, but failed to get the result I wanted. What are the other options?
That should be absolutely no problem - just put in the image, make layout constraints to the left and top of the view, then add the label right to it, and make layout constraints between the right side of the image and the left side of the text.
To restrict the label width you can add a constraint from the right side of the label to the right side of the view, if you want to make the label as small as possible with a greater-than sign.
EDIT
If the whole should be bound to the right border of the superview, put both in a view, align the view to the right border of the superview, and make a constraint from the right side of the label to the right side of the view. The view will resize accordingly when the label resizes.
I went for a solution where I added a third view as the leftmost element in a horizontal stackview and set the stackview's distribution as 'equal centering'. It actually fit well with the rest of the planned layout (all elements are used efficiently). Thank you for your help guys.
I am creating a view within IB and and attempting to have 3 UILabels evenly space horizontally across the view. I came across this on SO, https://stackoverflow.com/a/30249550/4597666. I have three UILabels, each have the height and width constrained. Here is what the IB looks like:
I constrained each centered horizontally, and the first UILabel I have the multiplier 3:1, second, 3:3, third 3:5 like the post states.
When I run on my emulator, I don't get the result that I was expecting. It appears all three UILabels are centered horizontally, and the first and third are not offset.
Is there another setting that I'm missing, or another way to properly space the views evenly?
you need to make only one change.
Constraint you set is 3.CenterX to Superview.CenterX all you need to do is interchange the value so that you constraint should look like in below image.
Alternative solution. If you want to set constraints currently you have set then change the ratio from "3:5" to "5:3" and similar for all the labels.
Result:
Hope it helps you solving your problem.
I am learning auto layout from last two days, i have one UITableViewCell xib file and in this cell there is two Labels and one Button, How can i manage Horizontally and vertically space between this subviews of cell?
Thanks in advance.
This trick is to add empty placeholder UIViews between your labels/buttons and bind them with an Equal Width constraint.
Following images show how it is done for horizontal spacing. Purple colored views are the placeholder UIViews. You can later set their alpha=0 or make them hidden so they will not appear when the app is running.