An elegant and curved modal View for iOS (Swift)
To run the example project, clone the repo, and run pod install
from the Example directory first.
The Example project use the modal as a Color/Size Picker.
D2PCurvedModal is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'D2PCurvedModal'
D2PCurvedModal
to your fileimport D2PCurvedModal
D2PCurvedModalTransition
and D2PCurvedModalPercentDrivenTransition
inside the your presenting ViewController
let percentDrivenTransition = D2PCurvedModalPercentDrivenTransition()
let transition = D2PCurvedModalTransition()
ViewController
must conform the UIViewControllerTransitioningDelegate
protocol, with these appropriate methodsextension ViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if presented is D2PCurvedModal {
transition.opening = true
return transition
}
return nil
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if dismissed is D2PCurvedModal {
transition.opening = false
return transition
}
return nil
}
func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return percentDrivenTransition.transitionInProgress ? percentDrivenTransition : nil
}
}
D2PCurvedModal
, to finally use the method setUpViewOf(viewController:)
of D2PCurvedModal
@IBAction func openModal(_ sender: Any) {
let myCustomVC = MyCustomVC(nibName: "MyCustomVC", bundle: Bundle(for: MyCustomVC.self))
let modalVC = D2PCurvedModal(nibName: "D2PCurvedModal", bundle: Bundle(for: D2PCurvedModal.self))
modalVC.setUpViewOf(viewController: myCustomVC)
modalVC.containerHeight = 200
modalVC.transitioningDelegate = self
percentDrivenTransition.attachToViewController(viewController: modalVC)
present(modalVC, animated: true, completion: nil)
}
That's it! You're all set!!
All of the methods and properties available for D2PCurvedModal are documented below.
containerHeight
Property (CGFloat) (Default: 300)Use the containerHeight
property of D2PCurvedModal
to change the height of the container view.
Example usage:
modalVC.containerHeight = 200
bgColor
Property (UIColor) (Default: .white)Use the bgColor
property of D2PCurvedModal
to change the background color of the modal view.
Example usage:
modalVC.bgColor = .orange
modalTitle
Property (String) (Default: "")Use the modalTitle
property of D2PCurvedModal
to change the title of the modal.
Example usage:
modalVC.modalTitle = "Filter"
modalTitleColor
Property (UIColor) (Default: .lightGray)Use the modalTitleColor
property of D2PCurvedModal
to change the title text color.
closeBtnBgColor
Property (UIColor) (Default: #FD4741)Use the closeBtnBgColor
property of D2PCurvedModal
to change the background color of the modal close button.
closeBtnTintColor
Property (UIColor) (Default: .white)Use the closeBtnTintColor
property of D2PCurvedModal
to change the tint color of the modal close button.
containerVC
Property (UIViewController)Use the containerVC
property of D2PCurvedModal
to access the view controller of the view that is embedded into the D2PCurvedModal
.
close(animated: Bool, completion: (() -> Void)?)
methodUse the close
method of D2PCurvedModal
to manually close the modal.
D2PCurvedModal uses a delegate to receive modal change events. The delegate object must conform to the D2PCurvedModalDelegate
protocol, which is composed of the method:
modalWillOpen(modalVC: D2PCurvedModal)
Tells the delegate that the view of the specified modal view controller is about to be displayed.
modalWillClose(modalVC: D2PCurvedModal)
Tells the delegate that the view of the specified modal view controller is about to be removed.
No Requirement
Credits to Johny Vino for the UI Design inspiration. FlatIcon for the icons.
D2PCurvedModal is available under the MIT license. See the LICENSE file for more info.