SwipeOptions.swift 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Options.swift
  3. //
  4. // Created by Jeremy Koch.
  5. // Copyright © 2017 Jeremy Koch. All rights reserved.
  6. //
  7. import UIKit
  8. /// :nodoc:
  9. public typealias SwipeTableOptions = SwipeOptions
  10. /// The `SwipeOptions` class provides options for transistion and expansion behavior for swiped cell.
  11. public struct SwipeOptions {
  12. /// The transition style. Transition is the style of how the action buttons are exposed during the swipe.
  13. public var transitionStyle: SwipeTransitionStyle = .border
  14. /// The expansion style. Expansion is the behavior when the cell is swiped past a defined threshold.
  15. public var expansionStyle: SwipeExpansionStyle?
  16. /// The object that is notified when expansion changes.
  17. ///
  18. /// - note: If an `expansionDelegate` is not provided, and the expanding action is configured with a clear background, the system automatically uses the default `ScaleAndAlphaExpansion` to show/hide underlying actions.
  19. public var expansionDelegate: SwipeExpanding?
  20. /// The background color behind the action buttons.
  21. public var backgroundColor: UIColor?
  22. /// The largest allowable button width.
  23. ///
  24. /// - note: By default, the value is set to the table/collection view divided by the number of action buttons minus some additional padding. If the value is set to 0, then word wrapping will not occur and the buttons will grow as large as needed to fit the entire title/image.
  25. public var maximumButtonWidth: CGFloat?
  26. /// The smallest allowable button width.
  27. ///
  28. /// - note: By default, the system chooses an appropriate size.
  29. public var minimumButtonWidth: CGFloat?
  30. /// The vertical alignment mode used for when a button image and title are present.
  31. public var buttonVerticalAlignment: SwipeVerticalAlignment = .centerFirstBaseline
  32. /// The amount of space, in points, between the border and the button image or title.
  33. public var buttonPadding: CGFloat?
  34. /// The amount of space, in points, between the button image and the button title.
  35. public var buttonSpacing: CGFloat?
  36. /// Constructs a new `SwipeOptions` instance with default options.
  37. public init() {}
  38. }
  39. /// Describes the transition style. Transition is the style of how the action buttons are exposed during the swipe.
  40. public enum SwipeTransitionStyle {
  41. /// The visible action area is equally divide between all action buttons.
  42. case border
  43. /// The visible action area is dragged, pinned to the cell, with each action button fully sized as it is exposed.
  44. case drag
  45. /// The visible action area sits behind the cell, pinned to the edge of the table/collection view, and is revealed as the cell is dragged aside.
  46. case reveal
  47. }
  48. /// Describes which side of the cell that the action buttons will be displayed.
  49. public enum SwipeActionsOrientation: CGFloat {
  50. /// The left side of the cell.
  51. case left = -1
  52. /// The right side of the cell.
  53. case right = 1
  54. var scale: CGFloat {
  55. return rawValue
  56. }
  57. }
  58. /// Describes the alignment mode used when action button images and titles are provided.
  59. public enum SwipeVerticalAlignment {
  60. /// All actions will be inspected and the tallest image and first baseline offset of title text will be used to create the alignment rectangle.
  61. ///
  62. /// - note: This mode will ensure the image and first line of each button title and consistently aligned across the swipe view.
  63. case centerFirstBaseline
  64. /// The action button image height and full title height are used to create the aligment rectange.
  65. ///
  66. /// - note: Buttons with varying number of lines will not be consistently aligned across the swipe view.
  67. case center
  68. }