I have my login view designed with stackview. The stackview has five views(segmented control, two textfields, and two buttons)
I set the alignment as Fill and distribution to be Fill proportionally. However, I can not change the spacing between the subViews.
Right now the spacing is 10 but I want 20 spacing between the segmented control and the first textField and 5 spacing between the "Sign In" button and the "Forgot Password?" button.
I know I can just remove the stackviews and use auto layout to achieve my desired positioning but I want to use stackview to control the views during the rotations.
Can anyone please help me with this.
UIStackView has an instance method that applies custom spacing after the specified view.
func setCustomSpacing(_ spacing: CGFloat,
after arrangedSubview: UIView)
stackView.setCustomSpacing(20, after: segmenteControl)
Well what you can do is to add cushion view in stackView to get more space between two views ... clear that cushion view background color and fix its height accoeding to your. demand
Related
everybody some I'm having some trouble vertically centering the or label between the Sign in with apple button and also the login button. Keep in mind that I am creating the SIWA button programmatically and setting the constraints that way also. I have tried getting the origin y coordinate for both buttons, dividing them by 2 and then setting the vertical constraint from the login button to the or label to be (loginButton.frame.origin.y - (divided by 2 value)) but that doesn't seem to work. Thanks for your help.
There's a couple ways to solve this:
Put the 2 buttons and the label in a vertical UIStackview with distribution set to equal spacing. Stackviews are very flexible too, especially in more complex layouts.
Create an empty UIView that sits between the two buttons, then add the label as a subview and center it. Alternatively, you can create 2 spacer views with equal height constraints above and below the label:
V:|[Button][space][Label][spacer2(==spacer1)][Button2]|
Very easy approach: by default, UILabel centers its text vertically in its frame.
So,
constrain the Top of the Label to the Bottom of the top button
constrain the Bottom of the Label to the Top of the bottom button
All done :)
IMPORTANT: This is not a main view but a view I added on the main one and it has its size.
I'm trying to constraint this view in order to make it resizable on every iOS device. I want it to look exactly how you see it.
I followed multiple guides online but even if I do exactly what I see it doesn't seem to work for me.
Here's what I tried:
I set the cancel's button width, then I constrained it to the view (trailing, bottom, leading) and vertically in container. I did the same for the one above it but the bottom constraint was attached to the button.
As regards the view with a lot of square buttons I:
Constrained the view to the button below it (bottom), set its width, placed it vertically in container, top space to safe area (I have a navigation bar above my view) and trailing and leading space to view.
As regards the buttons inside my view I set equal widths and hights for each of them and then I constrained them all top leading trailing and bottom (they all have a space of 7 between them or their view).
None of this works since the blue sky view either becomes bigger and wider, either goes outside of the screen, either everything gets very weird... How could I do?
I think this question is a bit tricky to answer. But I'll try my best :D
So, the first thing I would do is to put the pink squares inside a stackView and let autolayout help us a little. Then I would constrain the blueSkyView.top .leading and .trailing. After constrain the stackView .top, .leading, .trailing, .bottom to the blueSkyView, so that blue sky view could enlarge to fit the stack inside.
Then constrain the buttons to the bottom, just like you made. Consider using some constraints of Greater than from blue sky to Random Color button, for example, guaranteeing they will never overlap.
If you want to make this view a square for very time while using different devices, you need to give a height constraint for the view and also a leading and trailing.
Then make an outlet for the height constraint. In the viewDidAppear method you should wright the below code:
heightConstraint.constant = myView.frame.size.width
I know similar questions were asked before but all of them do it programatically and I'm trying to do this in the storyboard.
I have a scroll view with top, bottom, leading and trailing constraints, with a view inside it that is pinned to all edges of the scroll view and has equal width and height #250. Inside that I have a stack view with 6 other views that will change their height dynamically based on how much text each label gets. And it all works fine except for the fact that it doesn't scroll even when content overflows.
What am I doing wrong?
Here's a look at the storyboard:
You need to remove the inner view height which = 250 , and pin the stackView to all it's edges
I have a horizontal ScrollView of 20 (110 * 130 point) UIViews contained within a StackView. Each UIView contains an image.
When certain UIViews are hidden the UIView width is maintained at 110points. However, spaces are left were the hidden UIView should be.
I have been practicing with a StackView of 3 UIViews and hiding the center UIView. This leaves a space in the middle...
I would like the 3rd UIView to move into the 2nd UIView position (middle) and perform this for subsequent UIViews later on.
Does anyone know how I could go about doing this? Is this even possible?
I was hoping to accomplish this with a UICollectionView, however, I don't think you can drag an image from UICollectionView to UIView
Drag and Drop Image from UICollectionView to UIView?
A storyboard isn't meant for these complex user interactions, so I recommend you programmatically create your stack view and then set its constraints programmatically as well. This let's you change elements' heights in your code easily. This might help you get started:
Add views in UIStackView programmatically
Let say, I have a horizontal ScrollView of 20 (110 * 130 point) UIViews contained within a StackView. Each UIView will contain an image and a label.
If I decide to hide certain UIViews from the StackView it changes/stretches the width of the UIView.
How would I be able to maintain the same width/height of the UIView?
So lets say if I decided to hide 19 UIViews contained within the StackView. Is it possible to only show 1 UIView (110 * 130) within the StackView?
I have tested this out using a StackView of 3 UIViews in Storyboard with no success.
If I get this to work then my plan is to programmatically code in the 20UIViews.
I would appreciate any help.
You need to set constraints for the views inside the stack view. So in your case, the width constraint isn't set for the UIViews and is therefore causing weird problems.
I recommend checking out this guide on working with stack views in storyboard : http://www.appcoda.com/stack-views-intro/