title: Swift UIScrollView - Correct Implementation for Only Vertical Scrolling
body: <p>In advance, I apologize as I would say that I'm a beginner with iOS programming.</p>
  
  <p>I want to use <code>UIScrollView</code> because the content to display exceed the height of the screen.
  Therefore, I would like only a vertical scroll and not a horizontal scrolling.</p>
  
  <p>I'm using the Storyboard to draw the views with <code>AutoLayout</code>.</p>
  
  <p>Here's are the screenshot of my <code>UIViewController</code> with the <code>UIScrollView</code> :</p>
  
  <p><img src="https://i.stack.imgur.com/FQkF1.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/ndByI.png" alt="enter image description here"></p>
  
  <p>Then I change the Label to a big text like that</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      self.label1Label.text = "Seize jours après la chute du président Blaise Compaoré, le Burkina Faso a un nouveau chef d'EtatA l'issue d'ultimes tractions, civils et militaires se sont accordés, lundi 17 novembre, sur le nom du diplomate Michel KafandoSeize jours après la chute du président Blaise Compaoré, le Burkina Faso a un nouveau chef d'EtatA l'issue d'ultimes tractions, civils et militaires se sont accordés, lundi 17 novembre, sur le nom du diplomate Michel Kafando"
      self.label1Label.numberOfLines = 0
      self.label1Label.sizeToFit()
  </code></pre>
  
  <p>My problem is that if I don't set manually a width for my contentView (inside the <code>UIScrollView</code>), the scrolling is horizontal, not vertical. (Look Screenshot below):</p>
  
  <p><img src="https://i.stack.imgur.com/tzb0s.png" alt="enter image description here"></p>
  
  <p>I've tried to set contentSize as I've seen in many google post but without success :</p>
  
  <pre><code>self.scrollView.contentSize = CGSizeMake(400.0, 600.0)
  </code></pre>
  
  <p>If I set a width manually for my contentview (<code>i.e : 320pts</code>), the scrolling will be vertical (GOOD) but then depending on the iphone size, it won't cover the whole width of the screen as shown in the following screenshot :</p>
  
  <p><img src="https://i.stack.imgur.com/2njhK.png" alt="enter image description here"></p>
  
  <p>The question is : what is the correct implementation to use <code>UIScrollView</code> to have a <code>contentView</code> that respect the autolayout constraint (<code>full screen  : 0top - 0bottom - 0left - 0right</code>) and the scrolling to be only vertical.</p>
  
  <p>Thanks a lot for your help!</p>