ContentOffset, ContentInset, and ContentSize in UI ScrollView

Tram Ho


UIScrollView has many properties, of which contentInset , contentOffset and contentSize are the three most used properties. Once you understand these properties, you can easily start with the stretchable toolbars or pinch in / pinch out with images.

1. Content Inset

Is the margin from UIScrollView to innerView . It is used in case we want to provide childView internal space. This property can only be set in code with a default value of 0 for top, bottom, left and right.

2. Content Offset

This is the current position after scrolling in the area. So the value of contentOffset will change every time the user scrolls up or scrolls down. This property can be set by code as well as the main thread, it will scroll up to the given position if that position exists.

3. Content Size

The size of the content in UIScrollView . Sometimes this property can be dynamic as paging or static as contact list. It can also be changed at runtime and can also be set by code.

UITableView and UICollectionView inherit from UIScrollView , so all of these properties appear in tableView and collectionView and can be used multiple times as a solution to problems encountered or to design new features.


Share the news now

Source : Viblo