Skip to content

wanderingfairy/BottomSheetDialog-ios

Repository files navigation

BottomSheetDialog

CI Status Version License Platform

simulator_screenshot_E561520E-8430-4B33-BA3E-CAFC2CB28C12 simulator_screenshot_FE64B750-971C-47E6-A1F5-776FDE8C275E

A library for using the bottom sheet dialog in iOS.

  • AutoLayout is supported.
  • You can apply cornerRadius to Sheet.
  • There are many customizable attributes.
  • Handling did Tap event using delegate.
  • Easy and simple to use.

Usage

1. init and set delegate

let sheet = BottomDialogView(titles: ["delete",
                                          "cancel"],
                             images: [UIImage(named: "trash")!
                                            .withRenderingMode(.alwaysOriginal),
                                      UIImage(named: "xmark")!
                                            .withRenderingMode(.alwaysOriginal)])
    sheet.delegate = self

2. Set Attributes

    sheet.titleFont = UIFont.systemFont(ofSize: 14, weight: .regular)
    sheet.sheetHeight = 56
    sheet.imageSize = CGSize(width: 30, height: 30)
    sheet.removeFromSuperviewWhenDidTap = true // default value is false
    sheet.sheetCornerRadius = 14
    sheet.sheetBottomPadding = view.safeAreaInsets.bottom
    sheet.sheetBorderWidth = 0.5
    sheet.sheetBorderColor = .gray

Here are all of the customizable attributes and their default values:

var sheetCornerRadius: CGFloat = 0
var sheetCornerRadiusOnlyTop = false
var sheetBorderWidth: CGFloat = 0
var sheetBorderColor: UIColor = .lightGray
var sheetHeight: CGFloat = 56
var sheetPadding: CGFloat = 0
var imageLeadingPadding: CGFloat = 16
var titleLeadingPadding: CGFloat = 20
var titleColor: UIColor = .black
var titleFont: UIFont = .systemFont(ofSize: 14, weight: .bold)
var titleAlignment: NSTextAlignment = .natural
var viewBackgroundColor: UIColor? = .black.withAlphaComponent(0.7)
var sheetBackgroundColor: UIColor = .white
var removeFromSuperviewWhenDidTap = false
var sheetBottomPadding: CGFloat = 0
lazy var imageSize: CGSize = CGSize(width: 28, height: 28)

But you can use the default settings without specifying anything.

3. Add subview and show()

view.addSubview(sheet)
sheet.show()

4. Event handling with delegate method

extension ViewController: BottomDialogDelegate { 
  func didTapSheet(title: String, tag: Int) {
    switch title {
    case "delete":
      print("delete")
    default:
      print(title)
    }
  }
}

If the removeFromSuperviewWhenDidTap setting is not set to true, you must manually call removeFromSuperview().

Requirements

iOS version >= 11.0
Swift version >= 5.0

Installation

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

pod 'BottomSheetDialog'

Author

wanderingfairy, [email protected]

License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published