How can I display a UIView under a UIScrollview with autolayout ?
I have a scrollview and a UIView below it(the grey box in image below).
Adding it has a footer inside the scrollview is not what I want because as you can see I have tabs that can scroll horizontally... The same view needs to be under each tabs. I programatically add child view's to my scroll view.
Is it possible to put a UIView outside the uiscrollview ? If not, how can I add it above every child view at the bottom ?
I have tried messing around with the constraints but nothing worked. I am stuck.
Thanks in advance !
Storyboard :
ScrollView constraints :
UIView constraints :
I found the solution. You need to drag a UIView above the UIScrollView and add a space to the top and bottom layout. Also, I added a leading and trailing space constraint.
Related
I have a followed this answer Putting a UIScrollview in a viewcontroller (storyboard) to embed a scrollview in a viewcontroller (Mine is vertically instead of horizontally).
All the constrains are working except the fact that the view bounces back when it is let go. I have tried a lot of different solution, but none is working! Please help, I'm using autolayouts my main goal is to be able to show all the buttons on the screen through scrolling.
EDIT:
I have been trying all types of ways to increase the contentSize, but nothing happens - the scrollview won't scroll properly. I tried different codes from people with the same problem, but the bouncing won't stop. Am I doing anything wrong on my constraints? This is extremely frustrating, please help. My constraints (using autolayout) (as I said, I followed this answer Putting a UIScrollview in a viewcontroller (storyboard))
You have to increase your scrollView's contentSize to fit all of it's sub views.
You should add subview to scrollview, then add all other views to that subview.
scrollView
contentView
subview_1
subview_2
Then add constraints between scrollView and contentView (leading, trailing, top, bottom) and contentView should have width and height constraints set properly (set width equal to scrollView width)... the content size will be calculated automatically.... just set height
Can't build content inside scroll view with autolayout. Yes, I've investigated a lot, read apple technical note and some articles, I know, that content view should be constrained with scroll view's superview but can't still achieve the desired result. I expect this result:
fixed or scrollable (for small screens) portrait mode
always scrollable landscape mode, not to loose or overlap my fixed content
my button (red view) should always be at the bottom
my photo (yellow view) should always be fixed size and not to loose content
(like in my wrong landscape mode)
Making this work is actually pretty easy. All you have to do are the following steps:
Add the UIScrollView as subview of your UIViewController`
Add the UIView as a subview of the UIScrollView
Add the UIButton as a subview of the UIViewController. Do not add it as a subview of the UIScrollView if you want it to stick to the bottom.
Then add the following constraints:
Pin the UIScrollView to the top, left and right of you UIViewControllers view
Pin the UIButtonto the left, right and bottom of your UIViewControllers view
Pin the UIButton top to the UIScrollView bottom
Pin the UIImageView top, horizontalCenter and bottom to the UIScrollView
Set the UIImageView height and width constraints
Set the UIButton height constraint
And that's it. Do not add anything to the UIScrollView contentView and do not set the contentSize programmatically! The contentSize ist set automatically by Auto Layout.
Here are screenshots of the constraints and the result:
I am working on application in which I have UIScrollView which contains 3 subViews(UIView) and each subView has different controls & has different height. This all works fine but when I added constraint to UIScrollView and subView then UIScrollView isn't working.
I also added constraint to all the controls in subviews.
So please suggest me how to solve this problem?
It happened because UIScrollView content height and width dynamic at run time.
So whenever you apply constraint on UIScrollView then add
1.X position
2.y Position
3.width
4.height
Take a View as SubView on UIScrollView now apply Constraint
1.Leading on UIScrollView
2.Trailing on ScrollView
3.Top
4.Bottom
5.Height
6.Width
Then it work fine
For constraints to work properly,
You need to add a child view to UIScrollView and add your 3 views to that child view.
The main UIView and child view should have equal width constraint set.
For reference see this
I'm trying to setup a scroll for a UIView within a UIScrollView.
My view hierarchy is:
UIView (Controller) > UIScrollView > UIView (I'll call this subView from this point on)
I have used the IB to set the layout. I set the top of the subView to be inline with the top of the UIScrollView frame. The subView is as wide as the UIScrollView frame and extends beyond the height of the UIScrollView frame.
In the subView I have UILabels (also set up using the IB). To test the scrolling, I have one label that is just peeking above the bottom border of the UIScrollView frame. When I run the app this label would ideally be able to scroll into view, however, there is no scrolling and the label is just appearing as being cut off where the UIScrollView frame ends.
In the ViewController.m I have the following:
- (void)viewDidLoad
{
self.scrollView.contentSize = self.scrollSubView.frame.size;
}
where scrollSubView is the UIView within the UIScrollView.
What am I missing (doing incorrectly) that is preventing the scroll from working?
Thanks for any assistance offered.
Possible Issue
Autolayout is on, and it won't let scrollview work as required.
Possible Solution
Check for autolayout of storyboard and untick it.
If you dont want to set it to off, you can follow this short video
which is wonderfull to deal scrolling with autolayout. :)
UIScrollView with autolayout on
I have a view controller with a UIScrollView. Inside that scrollview I have two UIViews. viewA sits onto of viewB. I am using Xcode 5 and auto layout in this project. What I would like to do is when viewA is hidden, move viewB to the top where viewA was sitting (technically, still sitting, just hidden).
I looked at this SO answer: How to use auto-layout to move other views when a view is hidden?
However it hasn't really helped me. I connected a IBOutlet which was a constant to the vertical spacing to the top of the scroll view and set it to 0.0f when viewA was hidden. However it makes no changes to my UI at all.
First get the Top Space to SuperView NSlayoutConstraints Outlets for both subViews and then do the following:-
[self.aView setHidden:YES];
if([self.aView isHidden])
{
self.bViewTopConstraint.constant = self.aViewTopConstraint.constant;
}
using this the second UiView will go to the place of first UIView.
For Scrollview you have to set the constraints value properly. No need to set any contentsize. Once you set the constriants scrollview will work automatically.
Check the attached screenshot.