I’m trying to achieve this layout using the interface builder
I’ve already tried to embedded the bottom button inside another stackview, also tried to set it out of the stack view but nothing works as expected what have now is this
And getting this result
Can someone tell me what constraints are missing or what is wrong with my current constraints?
You usually don't need to add too many constraints to the stack view's arranged subviews. Setting the distribution and alignment correctly is the key. The constraints involving Stop Button are either unnecessary or causing the conflict that you see in the console.
To position the stack view, you just need to pin its top, bottom, leading, trailing edges to the safe area. For example:
Then, set the alignment of all the stack views to "Fill", and the distribution of all the stack views to "Fill Equally".
Related
I have stacked a view has a stack of labels and a TableView in single stack view (as shown in the picture below), however it's giving me a constraints for the x and y position of the two views inside the main stack view. I tried adding constraints for both views but it didn't work.
Stack View Constraints error
It seems like you don't have constraints for the stack view itself.
You could click this blue icon to see your layout constraints(you should check both Horizon and Vertical).
Also, if your constraint has problems, you can see there is a red arrow, click it to see the error message.
I’ve been working on an app with a grid of buttons. The grid consists of 4 buttons per row, and (currently) 6 rows. In the storyboard, each row of buttons is in a horizontal stack view, and all 6 stack views are in a vertical stack view.
I don’t want all of the buttons to be visible all the time, so I’m turning them on and off with .isHidden. This is causing some problems when I run the app in the simulator:
I want all of the buttons to stay the same size, but if one or more buttons in a given row / stack view are hidden, the remaining buttons in that row adjust their sizes to fill the row. I’m guessing that a combination of constraints on the buttons and settings on the stack view will solve this, but I haven’t come up with the right combination yet.
If I start with, say, the first 3 rows of buttons all unhidden, then try to unhide a button in one of the other rows, all of the buttons disappear. However, if I ‘print’ the .isHidden state of each button, the ones that should be visible have .isHidden = false.
Any ideas for solving either of these problems?
Thanks in advance for any assistance.
To answer your first question...
When you hide a view in a UIStackView, auto-layout treats it as if it is "gone" --- the stack view will re-layout its arrangedSubviews as if that view was never there to begin with.
If you want this result:
Your best bet is probably to set the .alpha property of that view / button to 0. It will be completely invisible (so, in effect, "hidden") and the stack view will retain its current layout. And, controls with .alpha = 0 do not respond to touches (so you can't tap the invisible button).
For your second question, I'd recommend you re-post that question on its own. Make sure to include the code you're using that is not having the desired result.
See: How to Ask
Im making a custom keyboard, and wanting a label and a textField centered in the space left over the keyboard, I figured the proper way would be to incorporate them in a UIstackView, and then centering the stack. However, i'm having som issues with the stack resizing my textField, causing whatever text i enter to be clipped.
I tried adding compressionresistance and a number of different solutions, but its clear to me that im missing some information about how UIStackViews work. Usually i make them work, but the whole resizing part I dont understand.
The first two screens are without a stack, adding them as subview to the viewcontrollers view, and the second screenshot shows the stackView resizing my textfield everytime the keyboard is resigned.
How can i stop the stackview from resizing its contained views?
It seems UIStackView is inherently a auto layout component, and when it adds your arranged subviews, it automatically positions them using constraints.
Since the UIStackView is adding constraints of its own, and the best way I found to stop it, was to simply explicitly set the subviews constraits:
textField.widthAnchor.constraint(equalToConstant: 300).isActive = true
Apple doesnt like dynamic StackViews: "In general, you should not use dynamic stack views to simply implement a scratch-built table view clone." Read the
Apple Documentation on UIStackView for details.
I try to find out if there is a chance to let the user resize a subview within an window by dragging a vertical line. The line is the NSBoxobject taken from the interface builder library. Both subviews (tableviewand textview) should resize itself in the horizontal direction by dragging the line during runtime.
Any hints? Thanks!
Please forgive me if I have miss understood your question as it seems very basic and I feel I’m missing something! Your request can easily be achieved through Storyboard Interface Builder, in your Object Library search both Vertical Split View and Horizontal Split View, these are great tools to allow the user to increase or decrease split view requirements. You can drop your desired views into either! And auto sizing will be maintained during user endeavours, alternatively Stack Views can maintain similar effects.
Is it possible to set height of super view relying on summarized height and padding between its child elements using auto layout?
Basically I'm trying to fill subviews with text from remote server, views are changing height dynamically, but their superview (or container view in other words) is static.
See -intrinsicContentSize and -invalidateIntrinsicContentSize. I believe this alone will get you there in simple cases. As I understand it, other things (including superviews with constrained distance from edges of a subview) will be moved to accommodate a view that claims a minimum size that would break those other constraints (keeping your view visible, for example).
I'd love it if others would chime in to validate/invalidate/correct me here. I'm still wrapping my own head around the many details specific to Autolayout in practice.