StackView Horizontal Images - Maintain same images width if hidden - swift

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/

Related

Image view crush stackview constraints in swift?

I have some issue about my stackview contraints or imageview constraints ı dont know actually.Probably both . This is my stackview constraints stackViewConst and this my imageview constraints imaviewConstraints . When ı try to run ı expect everything looks awesome however unfortunately ı get this screen screen my stackview is lost.How ı can figure out this help me
Answer: add stackview height constraint
(or add stack view content resistence and content hugging priorities higher than those of your UIImageView)
Explanation:
Since you are using storyboard's Interface builder (IB) for creating constraints, as opposed to pure code. The IB uses feature of auto-constraints, which basically means that the IB can figure itself the layout and constraints based on what is displayed in your storyboard. The UIStackView is using some dynamic resizing (so that elements within stackview are properly layed out) and it is always good idea to give it size constraints, or at least size constraints to elements inside UIStackView , otherwise it might decide that every element has size of CGSize(height:0,width:0) You can also make priorities of your UIStackView higher than those of your UIImageView so that IB would prioritize the size of your stackview's constraints to those of your imageView

Storyboard Scrollview with StackView inside not scrolling

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

Hiding view in stack view in iOS 10

When I hide a UIView inside UIStackview, on iOS 11 it nicely removes the gap and brings the adjacent UIViews closer inside the UIStackView. However, on iOS 10 it will not move the adjacent views and just leave the gap for the hidden view. Is there a way to get around it without having to manually move the views.
Have you added your own height constraint to the UIView? It will cause a conflict with the constraint height = 0 generated by the UIStackView when the UIView is hidden on iOS 10. Just lower the Priority of UIView height constraint (e.g. 999) and the UI will update properly.

Move visible images in StackView closer to leading space

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

How to use UIScrollView in IB? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
steps for creating UIScrollView with Interface Builder
I am using UIScrollView for one of my view. I have added view first and then scroll view, then some controls over scroll view, all are added through IB. Every things works fine until the page is fit, some controls need to be added down that is exceeding the UIView length, I am not sure, how to add controls in IB in that case, So I have added programmatically, but my scrollview is not scrolling down, it is scrolling upto my view height, I have tried setting the new view height, scrollview's frame and content size nothing works, Can anyone please suggest me what to do now...
i) how to add control in IB more than its view length.(view height are disabled).
ii) How to make my scrollview which covers full view.
Create the view for the UIScrollView separately.
Technically, UIScrollView can hold controls directly in it. But that is not the point of it. You should always (if using IB) design the view separately and then place it inside the UIScrollView and set the contentSize property to the size of that view.
So, instead of putting contents directly in the UIScrollView in the main view, drag a separate view from the IB objects library on the nib (not on the main view).
Set the width of this view to the width of UIScrollView. Start placing controls on it and extend the height of view. For every new control to be placed, the height must be increased so as to hold that control. You should not place control outside a view from IB. (Although you can).
After designing the view, drag the view inside the UIScrollView and set the Y value of this view to 0. (When you drag a view inside UIScrollView it seems to upset it's Y value).
Now programmatically set the contentSize of UIScrollView to the size of this view. For this you'll need to create an IBOutlet for the UIView you just created.
myscrollview.contentSize = myview.frame.size;
And you're done.
-EDIT-
it is so simple. Follow the steps I'm giving you below you will get what you want.
decide the actual size that is the size in which you want your scroll view to display. say it is 100 * 5o.
set your UIView size also 100 * 50.
Now increase the scrollview hieght in nib.
add what you want
Now check upto what size you have reached.
Suppose it is reached upto 300
So set your contentsize 100 * 300 or 100 * 310 programmatically
In nib set scrollview size 100 * 50
Enjoy programming.
It's very simple, first remember your UIScrollView Frame and then just change UIScrollView frame's Y-position by subtracting 100 (e.g 0 to -100) and add same to height(460 to 560). Then simply add you controls at your required position by continuing this steps...
For eg:
ScrollView Frame (0,0,320,460)
after CHANGE:
(0,-100,320,560)
After finishing with controls adding simply set previous frame like:
(0,0,320,460)