Untitled

 avatar
unknown
plain_text
2 years ago
4.6 kB
6
Indexable
https://pastecode.io/s/qe4t7duo
struct UIView: View {
    var body: some View {
        ZStack(alignment: .topLeading) {
            GeometryReader { geometry in
                Image("Splash_Screen")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(dynamicWidth: 393, dynamicHeight: 852)
                    .clipped()
                   // .background(Color(red: 0.26666668, green: 0.59607846, blue: 0.8745098))
                
                ZStack(alignment: .topLeading) {
                    GeometryReader { geometry in
                        Text("Take control of your time  ")
                            .frame(dynamicWidth: 319, dynamicHeight: 74.67, alignment: .leading)
                            .font(.custom("Poppins-Bold", size: 32))
                            .foregroundColor(Color(white: 1.0))
                            .offset(dynamicX: 37, dynamicY: 268.67)
                        
                        Text("Set yourself achievable goals and block your time while achieving the things you want.")
                            .frame(dynamicWidth: 319, dynamicHeight: 63, alignment: .leading)
                            .font(.custom("Poppins-Medium", size: 18))
                            .foregroundColor(Color(white: 1.0))
                            .offset(dynamicX: 37, dynamicY: 363.33)
                        
                        Button(action: {}) {
                            Text("Get Started").lineLimit(1).font(.custom("Poppins-Medium", size: 18))
                                .frame(dynamicWidth: 319, dynamicHeight: 60, alignment: .center)
                        }
                        .aspectRatio(contentMode: .fill)
                        .font(.custom("Poppins-Medium", size: 18))
                        .background(Color(white: 1.0))
                        .offset(dynamicX: 37, dynamicY: 448.33)
                        
                        Text("By signing up, you agree to our Terms of service and Privacy Policy")
                            .frame(dynamicWidth: 319, dynamicHeight: 28.67, alignment: .center)
                            .font(.custom(".AppleSystemUIFont", size: 12))
                            .multilineTextAlignment(.center)
                            .foregroundColor(Color(red: 1.0, green: 1.0, blue: 1.0))
                            .offset(dynamicX: 37, dynamicY: 518.33)
                    }
                }
                .frame(dynamicWidth: 393, dynamicHeight: 567)
                .background(Color(white: 0.0, opacity: 0.0))
                .offset(dynamicX: 0, dynamicY: 251)
            }
        }
        .frame(dynamicWidth: 393, dynamicHeight: 852)
        .background(Color(.systemBackground))
        .edgesIgnoringSafeArea(.all)
    }
}

struct UIView_Previews: PreviewProvider {
    static var previews: some View {
        UIView()
            .previewLayout(.fixed(width: 393.0, height: 852.0))
            .previewInterfaceOrientation(.portrait)
            .preferredColorScheme(.light)
    }
}

// --------------------------------------------------------------------------------
// Dynamic Size Helper
// --------------------------------------------------------------------------------
struct DynamicSize {
    static private let baseViewWidth: CGFloat = 393.0
    static private let baseViewHeight: CGFloat = 852.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
    }
}

// --------------------------------------------------------------------------------
// Frame and Offset Helper
// --------------------------------------------------------------------------------
extension View {
    func frame(dynamicWidth: CGFloat? = nil, dynamicHeight: CGFloat? = nil, alignment: Alignment = .center) -> some View {
        frame(
            width: DynamicSize.getWidth(dynamicWidth ?? 0),
            height: DynamicSize.getHeight(dynamicHeight ?? 0),
            alignment: alignment)
    }

    func offset(dynamicX: CGFloat = 0, dynamicY: CGFloat = 0) -> some View {
        offset(x: DynamicSize.getOffsetX(dynamicX), y: DynamicSize.getOffsetY(dynamicY))
    }
}
Editor is loading...