title: What exactly are contentOffset& contentInset of ScrollView
body: <p>I have 2 questions about ScrollView. One is my major question, Another one is secondary confusion.</p>
  
  <p>1.What exactly are <code>contentOffset</code> and <code>contentInset</code> of <code>ScrollView</code>? I will give more Details below.</p>
  
  <p>2.I create a <code>ScrollView</code>, but it seems the <code>ScrollView</code> can't roll in any direction.Is the problem about offset? Or inset? I will give more Details below.</p>
  
  <p><strong><em>Details for question 1:</em></strong></p>
  
  <p>Sometimes <code>contentOffset</code> property and <code>contentInset</code> property seem to have lots of difference, but when I try to implement some of functions that relate to those two properties, I get confused.
  And I make a simple illustration here. Can you help me figure it out that which part is offset and which part is inset? </p>
  
  <p><a href="https://i.stack.imgur.com/xGIuW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xGIuW.png" alt="enter image description here"></a></p>
  
  <p><strong><em>Details for question 2:</em></strong></p>
  
  <p>I use following function to add a <code>ScrollView</code> </p>
  
  <pre><code> func addScrollView(){
              // assign a new ScrollView to "scroll" class member 
              scroll = UIScrollView(frame: CGRectZero)
              scroll!.translatesAutoresizingMaskIntoConstraints = false
              // change it to gray color to help recognising 
              scroll!.backgroundColor = UIColor.grayColor()
              self.view.addSubview(scroll!)
  
              //add some constraints,[you can neglect following part]
              let x = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
              self.view.addConstraint(x)
  
              let y = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterY, multiplier: 1/2, constant: 25)
              self.view.addConstraint(y)
  
              let left = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.LeadingMargin, multiplier: 1, constant: 10)
              self.view.addConstraint(left)
  
              let upperSpacing = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 50)
              self.view.addConstraint(upperSpacing)
  
              let w = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 10)
              self.view.addConstraint(w)
  
              let h = NSLayoutConstraint(item: scroll!, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: scroll!, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0)
              self.view.addConstraint(h)
              print("add scroll view Successed")
          }
  </code></pre>
  
  <p>And it is not able to roll. It can only contain few things(Buttons or TextFields...) to fill its size, rather than put more things at places where we can't see.</p>
  
  <p>So is the problem about setting outset &amp; inset ? How can I set to fix this? And If I do so, how can I add things(buttons..) to the un-shown places programatically?</p>
  
  <p>I hope you can tell me some things!  </p>