I have a view and I add a subview to this with the following Autolayout requirements:
If view width is greater than or equal to view height, then i want subview width to be 75% of view width and height to be 15 points,
If view width is less than view height, then I want subview width to be fixed 15 points and subview height to be equal to 75% of view height.
How do I express these constraints programatically.
Related
I'm having a main view with UIScrollview it's child and than another view as scrollview's child. After setting the scroll view's content size it's child view's height isn't increasing.
This is the hierarchy
-MainView
--Scrollview
---ContentView
i've set the scrollview's constraint as top bottom left right to 0.
The content view's constraints are top bottom left right to 0 and equal width and height to main view.
But the content view's height isn't increasing.
The content view's constraints are top bottom left right to 0 and
equal width and height to main view.
"...and height to main view"
That's it. Your content view's height is set to equal to the screen. Let the subviews of your scrollView (or subViews of your contentView) increase the total content height so that your scrollView could scroll vertically.
Just remove the height constraint from child view. It will make width equal to main view's width and height equal to the height of content view of scroll view.
This is my setup:
I do not know what I am doing wrong. The image view is bigger than the size of the view and of the scroll view. The constrains are set al followed:
Scroll view: equal heights to View * 0,5, equal width to View, center Y and X to View.
View (inside Scroll view): pinned all zero's inside Scroll view, equal heights and width. I also tried instead of equal heights and widths to center X and Y inside Scroll view, but it won't scroll.
How can I let the Scroll view scroll? Thank you.
Add a leading, trailing and top constraint and equal height of UIScrollView to superview with 0.5 multiplier. Now to your contentView (the UIScrollView subview), add a leading, trailing , top and bottom constraint. Also add equal height and width to UIScrollView. Set the height to a priority of 250. Add constraints for UIImageView inside this contentView.
Since the contentView will have a fixed height of low priority equal to the UIScrollView height. This fixed height constraint will break once the UIImageView total height(based on the constraints you add) will get larger than the UIScrollView height and the content will become scrollable. So at the very least you will always have a view half the screen size and become scrollable once the content becomes too large vertically.
You need to give contentSize to scrollview.
ScrollView.contentSize = CGSize(width: 1000, height: 500)
Which constrains have you given to imageview?
set constraint of imageview:
Trailing ,leading,top,bottom - 0 and also give height constraint.
I have this view hierarchy
I want my content to grow vertically in content view but not horizontally. so I want to constrain ContentView's width to be the same as device's width. How can I do this in Interface Builder?
Note: The image's width in Image View is bigger than device's width, so right now ContentView's size grows both vertically and horizontally
just add the constraints to content view as leading space,trailing space,top space,bottom Space along with fix content view width constraint as constant and then create the outlet for width constraint value and in view controller side write method as
-(void)viewDidLayoutSubViews
{
_scrollViewContentViewWidthConstraint.constant = self.view.frame.size.width;
}
I have a view at the bottom of my view controller which has the following constraints:
align centre horizontally
fixed aspect ratio (1:1)
proportional width to width of view controller
bottom space of -50
How do I make the bottom space constraint proportional to the height of the view using Auto Layout? Meaning that if the height of the view is 250, the bottom space will be -50, but if the height is 300, the bottom space will be -60, and so on (the proportion is fixed at 0.2)?
Use the multiplier value. You want the bottom of your view to be 0.8 times the bottom of the superview.
I have one screen where I have added 1 scroll view on self view. Tab bar and navigation bar both are there and for iPhone 4 view height is 455.I have added more content on scroll view.the height of scroll view and self view is same.but when i am unable to set content size for scroll view.even i set too it is not working.Please help me.
Thanks
Here is how to set up the size of the contentView in Auto Layout:
Add a view to your scrollView. This should be the only top level view on your scrollView and it will serve as your contentView.
Constrain the left, top, right, and bottom edges of this contentView to the left, top, right, and bottom of the scrollView with offsets of 0.
To size the contentView, add width and height constraints to the contentView. If you want it to scroll, the width and height must be larger than the width and height of the scrollView itself. If you only want to scroll vertically, set the width of the contentView to be equal to the width of the scrollView.