What exactly are contentOffset& contentInset of ScrollView

A few observations:

  • The contentOffset is where the user has currently scrolled within the scroll view. This obviously changes as the user scrolls. You don’t generally change this programmatically (unless you want to programmatically scroll somewhere, e.g. have a button to scroll to the top).

  • The contentInset is how much the content is visually inset inside the scroll view (i.e. what the “margins” within the scrollview are). You generally set this once in IB or in viewDidLoad, as the scroll view is instantiated.

  • The contentSize is how big the scrollable content is. Note, with autolayout, you don’t have to specify this manually, but rather is calculated by the constraints that you specified between the scroll view and its subviews (and the constraints for the subviews and between the subviews).

To get scrolling to work correctly, it is a combination of (a) the bounds of the scroll view, less any contentInset; and (b) the contentSize, as calculated for you from the constraints of the subviews.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)