0

I'm trying to create a dynamic UIView that holds some fixed graphics elements and some dynamic text. I can't find a tutorial, or something in documentation that works for my project. Below is my exploded view (my view with scrollView and main view's height is forced to 800 in iphone 5 view, only for the pourpose of this question) enter image description here

What do I want to acheive? The Header,the image,static view and static view 2 are all fixed, and they will not change with their contents. Label 1, Label 2 and the textarea will grow with their content size.

enter image description here

I have worked on this thing for about a day, and I need a little help because I can't achive any results. I have tried this solution:

solution 1

With this solution I can see in NSLog() the textview constraint that return a correct value

self.textViewHeightConstraint.constant = [textview sizeThatFits:CGSizeMake(textview.frame.size.width, CGFLOAT_MAX)].height; 

but the textarea frame at runtime remains the same.

i have tried also this tutorial:

solution 2

It works for me in a project with only a scrollview, content view and textview. When i try to use that logic in my project it doesn't work anymore.

I have tried many other solutions, so my questions are: How I can achive the desired result? Or maybe there's something ridiculously wrong in my layout setting? Or simply, is there someone that can point my to a tutorial that cover a similar view organization?

1 Answer 1

1

You should avoid having a complex nested subviews inside a UIScrollView with AutoLayout, you should instead put them inside a subView. The best thing to start with:

1: Place a single UIView inside your UIScrollView with leading/trailing/top/bottom constraints set to 0 to the UIScrollView.

2: Place all the subviews inside the one single UIView,

3: Once you change the text/dynamic content of any of the subViews inside the UIView, you just calculate the scrollView.contentSize and set it accordingly by code needed for a set of complex nested subviews.

Your better option:

Work with a UITableView instead, it has the scrollView methods and it handles the dynamic layouts for you very easy without all the spaghetti code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.