ActionSheetButton.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // ActionSheetButton.swift
  3. // Sheeeeeeeeet
  4. //
  5. // Created by Daniel Saidi on 2017-11-26.
  6. // Copyright © 2017 Daniel Saidi. All rights reserved.
  7. //
  8. /*
  9. This class is a base class for all action sheet buttons. It
  10. is not intended to be used directly. Instead, use the built
  11. in buttons or subclass it to create your own button type.
  12. */
  13. import UIKit
  14. open class ActionSheetButton: ActionSheetItem {
  15. // MARK: - Initialization
  16. public init(title: String, value: Any?) {
  17. super.init(title: title, value: value)
  18. }
  19. public init(title: String, type: ButtonType) {
  20. super.init(title: title, value: type)
  21. }
  22. // MARK: - Values
  23. public enum ButtonType {
  24. case ok, cancel
  25. }
  26. // MARK: - Functions
  27. open override func applyAppearance(_ appearance: ActionSheetAppearance) {
  28. self.appearance = customAppearance ?? ActionSheetButtonAppearance(copy: appearance.okButton)
  29. }
  30. open override func applyAppearance(to cell: UITableViewCell) {
  31. super.applyAppearance(to: cell)
  32. cell.textLabel?.textAlignment = .center
  33. }
  34. }
  35. // MARK: - ActionSheetItem Extensions
  36. public extension ActionSheetItem {
  37. var isOkButton: Bool {
  38. return value as? ActionSheetButton.ButtonType == .ok
  39. }
  40. var isCancelButton: Bool {
  41. return value as? ActionSheetButton.ButtonType == .cancel
  42. }
  43. }