BottomSheetView is a customizable, easy-to-use bottom sheet component for iOS apps. With the introduction of native bottom sheet support in iOS 15, many applications require similar functionality for earlier iOS versions. BottomSheetView addresses this need by providing a solution that is compatible with iOS 13 and above. It allows developers to quickly integrate a fully functional bottom sheet with customizable behaviors and animations.
Simulator.Screen.Recording.-.iPhone.15.-.2024-07-07.at.14.46.13.mp4
- Customizable appearance and transitions.
- Gesture-based interactions (pan and tap).
- Safe area awareness.
- Keyboard interaction handling.
- Dynamic height adjustment based on content.
- Compatibility with both iPhones and iPads.
To integrate BottomSheetView into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'BottomSheetView', '~> 1.0.1' To add BottomSheetView as a dependency to your Swift package, add it to the dependencies value of your Package.swift file:
dependencies: [
.package(url: "https://github.com/DevAmar1996/Bottomsheet", .upToNextMinor(from: "1.0.1"))
]To start using the component, you need to import Bottom SheetView into your project:
import BottomSheetViewTo create a custom bottom sheet view, you can design a .nib file with your desired UI components and layout. You then subclass BottomSheetView to integrate this custom design.
class SampleBottomsheetView: BottomSheetView {
// MARK: Lifecycle
override class func initFromNib() -> SampleBottomsheetView {
let className = String(describing: SampleBottomsheetView.self)
return Bundle.init(for: SampleBottomsheetView.self).loadNibNamed(className, owner: self, options: nil)!.first as! SampleBottomsheetView
}
}Integrating BottomSheetView with a custom implementation is straightforward. Here's how you can quickly declare and present a bottom sheet in your view controller using a custom subclass.
First, ensure you have created a custom bottom sheet class and the associated .nib file. Then, you can use the following snippet to instantiate and display the bottom sheet:
import UIKit
class YourViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Initialize and show the bottom sheet
let bottomSheet = SampleBottomSheet.initFromNib()
bottomSheet.show()
}
}Ensure that the bottom sheet adjusts correctly during device rotations by updating its constraints:
override func viewWill: Transition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { _ in
self.bottomSheet?.updateConstraintsForRotation(size: size)
}, completion: nil)
}