0

I'm attempting to make a horizontally scrollable text.

The text is dynamic, but very large, therefore I need a dynamic amount of horizontal space and the ability to scroll.

My tree :


enter image description here


I set my view to constraints 0, -20, -20, -340 ( top, left, right, bottom ) though I wish the bottom was dynamic as I'm never going to know how much text to use.

Then I set contraints to center my UILabels in the middle.

But when I run it, the app looks like this :

enter image description here

No sure what I might be missing.


My storyboard :


enter image description here

Stonz2
  • 6,306
  • 4
  • 44
  • 64
Trip
  • 26,756
  • 46
  • 158
  • 277
  • Not sure I understand what you want to achieve though... do you want the app to run how it is but with scrolling or completely different? Did you set the contentSize of the scrollview to the size of the content? – ChrisBorg Mar 04 '16 at 16:12
  • @ChrisBorg I'm trying to scroll vertically. Right now it goes horizontally. I didn't set a contentSize of the scrollView.. the content being dynamic, I'm not entirely sure how to.. My apologies for not explaining this more clearly! – Trip Mar 04 '16 at 16:19
  • I think you might need to set autolayout constraints on each item. The constraints on the scrollview need to be tied to the main view like the one you wrote. Then the view inside the scrollview need to have constraints tied to the scrollview, similar to the one in your question, but without a bottom constraint and a height constraint >= than a preferred height. Then add the constraints to the remaining items inside of the view to the view. Does this make sense? – ChrisBorg Mar 04 '16 at 16:43

1 Answers1

2

remove autolayout for this particular screen

yourView.translatesAutoresizingMaskIntoConstraints = false

and try to set all your frames including scrollview's size & its content in

- (void) viewDidAppear:(BOOL)animated 

good luck.

Maulik Bhuptani
  • 597
  • 3
  • 14
  • Thanks so much Maulik for responding. Question.. would I target `yourView` by ctrl + dragging my view to my ViewController.swift file? I tried something similar but it didn't seem to work. Just curious how you target such objects that you create within the UIBuilder. – Trip Mar 04 '16 at 20:30
  • If i am not understanding wrong, your want to create an external view(uiview or xib) and connect its objects to your viewcontroller.swift file. Select your xib, then change File's owner class to viewcontroller.swift. ctrl + dragging will then be possible. – Maulik Bhuptani Mar 05 '16 at 05:12
  • Ah ok that's how I link xib's to code. Didn't know that. So I can target my view now like you recommend. But that doesn't change anything. The text still is running horizontal, and it's view is not containing the text and allow my to scroll vertically. I assume it's because the view doesn't have explicit widths set. – Trip Mar 05 '16 at 17:20