ActionSheetMargin.swift 763 B

1234567891011121314151617181920212223242526272829303132
  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. if #available(iOS 11.0, *) {
  13. let insets = view.safeAreaInsets
  14. switch self {
  15. case .top: return insets.top
  16. case .left: return insets.left
  17. case .right: return insets.right
  18. case .bottom: return insets.bottom
  19. }
  20. } else {
  21. return 0
  22. }
  23. }
  24. func value(in view: UIView, minimum: CGFloat) -> CGFloat {
  25. return max(value(in: view), minimum)
  26. }
  27. }