Hello Community,
I was doing SwiftUI Views and basically tipped it off. But my code throws an error however the code from codecademy which is basically the same works fine. It’s for a quiz app.
//
// ContentView.swift
// Quiz App Codecademy Project I
//
// Created by ------ on 27.05.23.
//
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack
{
mainColor.ignoresSafeArea()
VStack
{
Text(“1 / 10”)
.font(.callout)
.multilineTextAlignment(.leading)
.padding()
Text(“What was the first computer bug?”)
.font(.largeTitle)
.bold()
.multilineTextAlignment(.leading)
Spacer()
HStack {
Button(action: {
print(“Tapped on Choice 1”)
}, label: {
Text(“Ant”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding() Here comes the error: Type ‘(Color?) → some View’ cannot
conform to ‘ShapeStyle’
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 2”)
}, label: {
Text(“Beetle”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 3”)
}, label: {
Text(“Moth”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 4”)
}, label: {
Text(“Fly”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
}
}
}
.foregroundColor(.white)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
let mainColor = Color(red: 20/255, green: 28/255, blue: 58/255)
let accentColor = Color(red: 48/255, green:105/255, blue: 240/255)