There are 7 labels in 7 UIView and UIViews are inside StackView. I want just one view ( middle one) has more width than others because labels don't fit. Is there any way to do that?
When I change StackView from Fill Equally to Fill Proportionally.
I think you should set fill proportionally in distribution field.
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'm starting with iOS app and creating a table view. In my table I have a cell like this.
Now I need to center the horizontal stackview with stars vertically and horizontally. This stackview has fixed width and height.
It have to look like this.
For this I put it in another horizontal stackview. I tried to add the same constraints to it as you see for the label
The problem is that this external stackview does not stretch like a label. I also see that it's width and height are greyed out, I cannot change them. Why?
There are many ways to autolayout this.
I think you should gain a better understanding of StackViews for future usage.
I recommend reading on these resources:
https://developer.apple.com/documentation/uikit/uistackview
https://www.raywenderlich.com/160646/uistackview-tutorial-introducing-stack-views-2
In order to achieve what you need:
Use only 1 horizontal StackView containing the stars. Constraint the stackview to the label by center horizontally.
Use 2 StackViews and keep your constraints. Outer stackview, change it to vertical axis and center alignment.
Method 2 Image in Attributes Inspector (cmd + option + 4):
I have a horizontal UIStackView with 2 views within it. I'd like to have the left view take up ~70% of the screen, and the right view take up the remaining 30%. I know that I can set the UIStackView alignment to Fill and the distribution to Fill and that will allow me to have more control over my subview sizes. What I can't figure out is how to set the layout constraints/widths/etc. on the subviews so that the the 70/30 ratio is correct, particularly when the device is rotated?
Can anyone explain how to set the constraints on my subviews so that the 70/30 ratio is maintained across device rotations?
You should be able to do this by creating an equal width constraint for the two views. Then, set the multiplier to that constraint to 0.7.
I'm creating a UI using size classes. As you can see in the below picture , there's issue with iPhone 6 Plus . Please help iPhone 4s always creates a mess. Do tell me if the UI is correct?
Image description:
Hope this helps!!
Select Login Merchant button, Blue and Pink button with OR label and put them in Stack View with Vertical axis. name it as (Bottom StackView)
Put some proper spacing between them.
If your image height is not fixed then make it relative to the device height, that means create a height constraint of imageView = (1/3)height of mainView.
Also you can take Label and textField Username in Horizontal StackView then combine both textFiled (username and pass) and Label in Vertical StackView.
Make vertical constraints Greater Than Equal to 20 between Bottom StackView and Center StackView.
this will give to better result in all screens.
In Case if you don't use StackView then,
Combine Bottom 3 button in SingleView (BottomView) and Upper textFields and Labels in SingleView (CenterView).
Then set vertical spacing s Greater Than Equal to 20 between them.
Make your image height as relative to screen size as described above.
The issue : Image take most of the stack and text shrinks
I tried to change content hugging priority but no changes !
How to do it in UIStackview using storyboard?
What I want the cell to look like Eventbright event Cell?
What I got is an image that take most of the cell?
Instead of Fill, change the Distribution of the UIStackView to Fill Proportionally and add constraints for the width of each element. Those constraints will serve as a guide to proportions on one element to each other and not as fixed sizes.
I tried it the following way.
The overall set up is given in pic:
At run time result is as given:
First Stack view is fill proportionally
imageview width is 1:4 of stackview width (control and drag from imageview to stackview and set equal width to 25% )
From control and drag select equal width. as shown
stack view 2 is fill equally
stack view 3 is fill equally
Hope it can help