Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Converted by Storyboard to SwiftUI Converter - https://swiftify.com/#/converter/storyboard2swiftui
- import SwiftUI
- // --------------------------------------------------------------------------------
- // OverviewController
- // --------------------------------------------------------------------------------
- struct Overview: View {
- var body: some View {
- ZStack(alignment: .topLeading) {
- GeometryReader { geometry in
- Image("")
- .frame(width: DynamicSizeHelper.getWidth(180), height: DynamicSizeHelper.getHeight(180))
- .offset(x: DynamicSizeHelper.getOffsetX(250), y: DynamicSizeHelper.getOffsetY(44))
- Button(action: {}) {
- .frame(width: DynamicSizeHelper.getWidth(75), height: DynamicSizeHelper.getHeight(32))
- }
- .foregroundColor(Color.white)
- .offset(x: DynamicSizeHelper.getOffsetX(93), y: DynamicSizeHelper.getOffsetY(89))
- }
- }
- .frame(width: DynamicSizeHelper.getWidth(450), height: DynamicSizeHelper.getHeight(244))
- .edgesIgnoringSafeArea(.all)
- }
- }
- struct Overview_Previews: PreviewProvider {
- static var previews: some View {
- Overview()
- }
- }
- // --------------------------------------------------------------------------------
- // SwiftUI View Extension
- // --------------------------------------------------------------------------------
- extension View {
- /// Hide or show the view based on a boolean value.
- ///
- /// Example for visibility:
- /// ```
- /// Text("Label")
- /// .isHidden(true)
- /// ```
- ///
- /// Example for complete removal:
- /// ```
- /// Text("Label")
- /// .isHidden(true, remove: true)
- /// ```
- ///
- /// - Parameters:
- /// - hidden: Set to `false` to show the view. Set to `true` to hide the view.
- /// - remove: Boolean value indicating whether or not to remove the view.
- @ViewBuilder func isHidden(_ hidden: Bool, remove: Bool = false) -> some View {
- if hidden {
- if !remove {
- self.hidden()
- }
- } else {
- self
- }
- }
- }
- // --------------------------------------------------------------------------------
- // Dynamic Size Helper
- // --------------------------------------------------------------------------------
- struct DynamicSizeHelper {
- static private let baseViewWidth: CGFloat = 375.0
- static private let baseViewHeight: CGFloat = 667.0
- static func getHeight(_ height: CGFloat) -> CGFloat {
- return (height / baseViewHeight) * UIScreen.main.bounds.height
- }
- static func getWidth(_ width: CGFloat) -> CGFloat {
- return (width / baseViewWidth) * UIScreen.main.bounds.width
- }
- static func getOffsetX(_ x: CGFloat) -> CGFloat {
- return (x / baseViewWidth) * UIScreen.main.bounds.width
- }
- static func getOffsetY(_ y: CGFloat) -> CGFloat {
- return (y / baseViewHeight) * UIScreen.main.bounds.height
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement