Skip to content

dmillerconsulting/FittedSheets

 
 

Repository files navigation

FittedSheets

Bottom sheets for iOS

Demo

About

This project is to enable easily presenting view controllers in a bottom sheet that supports scrollviews and multiple sizes. Contributions and feedback are very welcome.

Usage

Using a bottom sheet is simple.

The constructor is init(controller:, sizes:). Sizes is optional, but if specified, the first size in the array will determine the initial size of the sheet.

Using default settings

let controller = MyViewController()

let sheetController = SheetViewController(controller: controller)

self.present(controller, animated: false, completion: nil)

Customizing settings

let controller = MyViewController()

let sheetController = SheetViewController(controller: controller, sizes: [.fixed(100), .fixed(200), .halfScreen, .fullScreen)
sheetController.blurBottomSafeArea = false
sheetController.adjustForBottomSafeArea = true

self.present(controller, animated: false, completion: nil)

Settings

/// Determines if we should inset the view controller to account for the bottom safe area.
/// If your view controller already handles this, leave it false (the default)
/// If your view controller does *not* handle this, set it to true
var adjustForBottomSafeArea: Bool = false
/// Determines if we blur the contents under the bottom safe area (if there is a safe area)
/// The default value is true
var blurBottomSafeArea: Bool = true
/// The color of the overlay above the sheet.
var overlayColor: UIColor = UIColor(white: 0, alpha: 0.7)
/// Sets the heights the sheets will try to stick to. It will not resize the current size, but will affect all future resizing of the sheet.
func setSizes(_ sizes: [SheetSize])
/// This should be called by any child view controller that expects the sheet to use be able to expand/collapse when the scroll view is at the top.
func handleScrollView(_ scrollView: UIScrollView)

There is an extension on UIViewController that gives you a sheetViewController that attempts to find the current SheetViewController so you can attach like this:

override func viewDidLoad() {
  super.viewDidLoad()
  
  self.sheetViewController?.handleScrollView(self.scrollView) // or tableView/collectionView/etc
}

Cocoapods

The easiest way to integrate the project is through cocoapods.
Add this to your podfile to add FittedSheets to your project.

pod 'FittedSheets'

License

FittedSheets uses the MIT License:

Please see included LICENSE file.

About

Bottom sheets for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%