Advertisement
IbrahimHassan

Untitled

May 25th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. // Converted by Storyboard to SwiftUI Converter - https://swiftify.com/#/converter/storyboard2swiftui
  2.  
  3. import SwiftUI
  4.  
  5. // --------------------------------------------------------------------------------
  6. // OverviewController
  7. // --------------------------------------------------------------------------------
  8. struct Overview: View {
  9. var body: some View {
  10. ZStack(alignment: .topLeading) {
  11. GeometryReader { geometry in
  12. Image("")
  13. .frame(width: DynamicSizeHelper.getWidth(180), height: DynamicSizeHelper.getHeight(180))
  14. .offset(x: DynamicSizeHelper.getOffsetX(250), y: DynamicSizeHelper.getOffsetY(44))
  15.  
  16. Button(action: {}) {
  17. .frame(width: DynamicSizeHelper.getWidth(75), height: DynamicSizeHelper.getHeight(32))
  18. }
  19. .foregroundColor(Color.white)
  20. .offset(x: DynamicSizeHelper.getOffsetX(93), y: DynamicSizeHelper.getOffsetY(89))
  21. }
  22. }
  23. .frame(width: DynamicSizeHelper.getWidth(450), height: DynamicSizeHelper.getHeight(244))
  24. .edgesIgnoringSafeArea(.all)
  25. }
  26. }
  27.  
  28. struct Overview_Previews: PreviewProvider {
  29. static var previews: some View {
  30. Overview()
  31. }
  32. }
  33.  
  34. // --------------------------------------------------------------------------------
  35. // SwiftUI View Extension
  36. // --------------------------------------------------------------------------------
  37. extension View {
  38. /// Hide or show the view based on a boolean value.
  39. ///
  40. /// Example for visibility:
  41. /// ```
  42. /// Text("Label")
  43. /// .isHidden(true)
  44. /// ```
  45. ///
  46. /// Example for complete removal:
  47. /// ```
  48. /// Text("Label")
  49. /// .isHidden(true, remove: true)
  50. /// ```
  51. ///
  52. /// - Parameters:
  53. /// - hidden: Set to `false` to show the view. Set to `true` to hide the view.
  54. /// - remove: Boolean value indicating whether or not to remove the view.
  55. @ViewBuilder func isHidden(_ hidden: Bool, remove: Bool = false) -> some View {
  56. if hidden {
  57. if !remove {
  58. self.hidden()
  59. }
  60. } else {
  61. self
  62. }
  63. }
  64. }
  65.  
  66. // --------------------------------------------------------------------------------
  67. // Dynamic Size Helper
  68. // --------------------------------------------------------------------------------
  69. struct DynamicSizeHelper {
  70. static private let baseViewWidth: CGFloat = 375.0
  71. static private let baseViewHeight: CGFloat = 667.0
  72.  
  73. static func getHeight(_ height: CGFloat) -> CGFloat {
  74. return (height / baseViewHeight) * UIScreen.main.bounds.height
  75. }
  76.  
  77. static func getWidth(_ width: CGFloat) -> CGFloat {
  78. return (width / baseViewWidth) * UIScreen.main.bounds.width
  79. }
  80.  
  81. static func getOffsetX(_ x: CGFloat) -> CGFloat {
  82. return (x / baseViewWidth) * UIScreen.main.bounds.width
  83. }
  84.  
  85. static func getOffsetY(_ y: CGFloat) -> CGFloat {
  86. return (y / baseViewHeight) * UIScreen.main.bounds.height
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement