ContentFitScrollView 3.0.0

ContentFitScrollView 3.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2018
SPMSupports SPM

Maintained by Anton Plebanovich.



  • By
  • Anton Plebanovich

ContentFitScrollView

Carthage compatible Version License Platform CI Status

Self adjustable Scroll View that proportionally reducing provided height constraints constants to fit all content on screen without scrolling. It takes into account ContentFitLayoutConstraint's minimumHeight value. If it's unable to fit content on screen without scrolling it'll just allow scrolling.

ContentFitScrollView allows you to layout your content for high resolution screens and be sure that in case there isn't enough space on lower resolution screens content will be scrollable.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Demonstration

About iPhone screens - https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

Let's assume designer did his job well and provided me 1242x2208 images. In my turn I did everything to match original. So 7 Plus images are ideal ones. Now let's compare how my interface will look like on other devices.

Without ContentFitScrollView

7 Plus 6s 5s

No doubt it looks awful on every device except top ones (iPhone 6+, 6s+, 7+). My goal here was to fit everything on screen and with simple layout I failed. Of course I could use constraints to labels center and layout them acording to container view's center... But it's headache to calculate all those multipliers and expecially recalculate them when new designs arrive. Now try to imagine that layout won't be that simple... Ugh...

With ContentFitScrollView

7 Plus 6s 5s

This one much better! ContentFitScrollView tries to reduce available space between labels to fit them all on screen. In case it can't screen will be scrollable so in worst case we fallback to how UIScrollView works.

With ContentFitScrollView + APExtensions

7 Plus 6s 5s

I'm using UILabel+Storyboard extension from APExtensions/Storyboard to fit labels to screen size.

This one solution almost guarantee that my screen never will be scrollable and all elements will fit to screen. But for some layouts I still might preffer second one. It's up to you to decide which one fits better for your needs.

Installation

Carthage

If you are setting ContentFitScrollView class in storyboard assure module field is also ContentFitScrollView

Please check official guide

Cartfile:

github "APUtils/ContentFitScrollView"

CocoaPods

ContentFitScrollView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ContentFitScrollView'

Usage

Just set ContentFitScrollView class to UIScrollView in storyboard (usually it's base container), assure module field is also ContentFitScrollView:

and add constraints that you want to be resized in order to fit content for screen:

You can set ContentFitLayoutConstraint class for those constraints in order to specify minimum height.

See example project for more details.

Contributions

Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.

Author

Anton Plebanovich, [email protected]

License

ContentFitScrollView is available under the MIT license. See the LICENSE file for more info.