ActionSheetMargin.swift 874 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // ActionSheetMargin.swift
  3. // Sheeeeeeeeet
  4. //
  5. // Created by Daniel Saidi on 2018-02-22.
  6. // Copyright © 2018 Daniel Saidi. All rights reserved.
  7. //
  8. import UIKit
  9. public enum ActionSheetMargin {
  10. case top, left, right, bottom
  11. func value(in view: UIView?) -> CGFloat? {
  12. guard let view = view else { return nil }
  13. if #available(iOS 11.0, *) {
  14. let insets = view.safeAreaInsets
  15. switch self {
  16. case .top: return insets.top
  17. case .left: return insets.left
  18. case .right: return insets.right
  19. case .bottom: return insets.bottom
  20. }
  21. } else {
  22. return nil
  23. }
  24. }
  25. func value(in view: UIView?, minimum: CGFloat) -> CGFloat {
  26. guard let value = self.value(in: view) else { return minimum }
  27. return max(value, minimum)
  28. }
  29. }