I am making a SwiftUI app and am giving it that "neomorphic" design but my issue is that since I use absolute positioning (due to the fact that I couldn't find any other viable solution), the app looks good on the iPhone 12 Pro and looks terrible on the other phones/tablets. I tried using Spacer() but I couldn't seem to understand on how to make the top "banner" into the size I want.
My code
//
// ContentView.swift
import SwiftUI
extension Color {
static let offWhite = Color(red: 225 / 255, green: 225 / 255, blue: 235 / 255)
static let superoffwhite = Color(red: 215 / 255, green: 215 / 255, blue: 225 / 255)
static let hellocolor = Color(red: 183 / 255,green: 114 / 255,blue: 126 / 255)
static let StartPlayingColor = Color(red: 114 / 255,green: 138 / 255 ,blue: 183 / 255)
}
extension LinearGradient {
init(_ colors: Color...) {
self.init(gradient: Gradient(colors: colors), startPoint: .topLeading, endPoint: .bottomTrailing)
}
}
struct ContentView: View {
var body: some View {
ZStack {
Color.offWhite
RoundedRectangle(cornerRadius: 98)
.fill(Color.superoffwhite)
.frame(width: 422, height: 459)
.position(x:183, y: 125)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 10, y: 10)
.shadow(color: Color.white.opacity(0.7), radius: 10, x: -5, y: -5)
Text("Hello\nAmit")
.foregroundColor(Color.hellocolor)
.font(Font.custom("Rubik", size: 72))
.multilineTextAlignment(.center)
.position(x: 183, y: 180)
Button(action: {
print("Button tapped")
}) {
Text("Start Playing")
.foregroundColor(.StartPlayingColor)
.position(x: 193, y: 382)
}
.buttonStyle(SimpleButtonStyle()).position(x: 193, y: 486)
}
}
}
struct SimpleButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.background(
Group {
if configuration.isPressed {
RoundedRectangle(cornerRadius: 98) .fill(Color.superoffwhite)
.overlay(
RoundedRectangle(cornerRadius: 98)
.stroke(Color.gray, lineWidth: 4)
.blur(radius: 98)
.offset(x: 2, y: 2)
.mask(Circle().fill(LinearGradient(Color.black, Color.clear)))
)
.overlay(
RoundedRectangle(cornerRadius: 98) .stroke(Color.white, lineWidth: 8)
.blur(radius: 98)
.offset(x: -2, y: -2)
.mask(Circle().fill(LinearGradient(Color.clear, Color.black)))
)
.frame(width: 242, height: 91)
}
else {
RoundedRectangle(cornerRadius: 98) .fill(Color.superoffwhite)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 10, y: 10)
.shadow(color: Color.white.opacity(0.7), radius: 10, x: -5, y: -5)
.frame(width: 242, height: 91)
}
}
)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Picture of App on Multiple Devices
Any help would be greatly Appreciated!