Reputation: 543
I am having a problem sizing a uiView inside of my uiScrollView to contain all of its subviews. Here is am image of my layout (I shaded the UIView within the scroll view blue to highlight the problem)
Here is what happens, though when I launch the app. This is what is rendered
As you can see the blue content view is only sized to the screen dimensions of the phone, and all subviews below that are outside of the frame and I cannot interact with them. Can anyone tell me how scale this content view properly? This is an older app and I cannot use auto-layouts, only springs and struts.
Upvotes: 2
Views: 890
Reputation: 3677
For ManualLayout
You can simply use to get the height and y position of you last entered object.
Lets say you last added object is a UIView
so just add this code.
self.scrollView.constentSize = CGSizeMake(self.scrollView.frame.size.width + (lastAddedView.frame.origin.y + lastAddedView.frame.size.height /* Here you can add some more space if you feel neccessory*/));
Upvotes: 1
Reputation: 3677
For Autolayout
with UIScrollView
There is a Special Technique that we should follow.
UIScrollView
inside this view with the same size and set the constraints 'Top, Bottom, Leading and Trailing equals to 0'UIScrollView
And set the constraints 'Top, Bottom, Leading and Trailing equals to 0'. This will still show red (which means constraints are still not correct) So Control + drag to the parent view of ScrollView that we have created in beginning and set equal width and equal height. Select the equal height constraint and decrease the priority to 750 in the property attribute on the right side of Xcode.Note: You must have change the value of bottom constraint after adding constraint not while adding constraint.
Upvotes: 1