I'm new to swiftui and started to somewhat catch on. But the main problem where I face is creating an app for different screen sizes. This is leading me to a bottleneck for creating apps. I try to solve this problem by enclosing the whole code in GeometryReader{ geometry in ...} and then specifying the sizes(width, height) as well .position of various elements by using the geometry. example code added. Yet when I switch screen sizes it looks like a mess. I have been stuck on this for a long time. Please correct me if I'm using a completely wrong approach.
struct CarInfoCard: View {
@State var cardValue: String
@State var cardUnit: String
@State var cardType: String
@State var cardNotify: Bool
@State var geo: GeometryProxy
var body: some View {
VStack(alignment: .leading){
HStack(alignment: .lastTextBaseline, spacing: 2) {
Text(cardValue)
//.font(.system(size: 40, weight: .bold, design: .rounded))
.font(.title)
.bold()
.foregroundColor(Color("ColorButtonLogo"))
Text(cardUnit)
// .font(.system(size: 25, weight: .bold, design: .rounded))
.font(.title3)
.bold()
.foregroundColor(Color("ColorButtonLogo"))
}
Text(cardType)
//.font(.system(size: 15, design: .rounded))
.font(.subheadline)
.foregroundColor(Color("ColorButtonLogo"))
}
.frame(width: geo.size.width/3.5, height: geo.size.height/10,alignment: .leading)
.frame(maxWidth:100)
.padding(.vertical,5)
// .padding(.bottom, 5)
//.padding(.leading, 10)
.padding(.horizontal, 5)
.background(Color("ColorButton"))
//.cornerRadius(20)
.cornerRadius(geo.size.width/30)
.shadow(color: Color.black.opacity(0.15), radius: 20, x: 10, y: 10)
}
}