StickyFooterScrollView is developed for quick creation of UIScrollView to implement

StickyFooterScrollView

StickyFooterScrollView is developed for quick creation of UIScrollView to implement. Usually when creating UIScrollView, developers have to declare and adjust many complex UI constraints to use, StickyFooterScrollView was developed to solve the above problem. StickyFooterScrollView focuses on quick initialization of UIScrollView and its ease of use with a few declared simple functions

Example

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

Requirements

Installation

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

pod 'StickyFooterScrollView'

Usage

import StickyFooterScrollView
  1. Initiate StickyFooterScrollView
let scrollView = StickyFooterScrollView(minimumFooterTopOffset: 24)
  1. Add StickyFooterScrollView into parent
view.addSubview(scrollView)
  1. Setup constraints for StickyFooterScrollView

scrollView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
    scrollView.topAnchor.constraint(equalTo: view.topAnchor),
    scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
  1. Setup content view and add into StickyFooterScrollView to display the main content

let mainContentView = UIStackView()
mainContentView.axis = .vertical

let imageView = UIImageView(image: UIImage(named: "Image"))
mainContentView.addArrangedSubview(imageView)

let titleLabel = UILabel()
titleLabel.text = "Hello"
titleLabel.textColor = .red
mainContentView.addArrangedSubview(titleLabel)

let descriptionLabel = UILabel()
descriptionLabel.text = "Sticky Footer Scroll View"
descriptionLabel.textColor = .blue
mainContentView.addArrangedSubview(descriptionLabel)
        
scrollView.applyContentView(mainContentView, with: .init(top: 24, left: 24, bottom: 24, right: 24))
  1. Setup the footer view and add into StickyFooterScrollView to display the footer content

let confirmButton = UIButton()
confirmButton.setTitle("OK", for: .normal)

scrollView.applyFooterView(confirmButton, with: .init(top: 24, left: 24, bottom: 24, right: 24))
  1. On function viewDidAppear, call the function updateLayout for constraint UI

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

contentView.scrollView.updateLayout()
}

Author

fanta1ty, thinhnguyen12389@gmail.com

License

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

GitHub

View Github