Hello,
I’m currently working on building an app with SwiftUI (Code History app); however, as i’m typing out the code for the buttons, whenever I’m using padding(), I keep getting an error that says: Type’(Color?) → some View’ cannot conform to ‘ShapeStyle’.
Can anyone please help me out with this because I don’t know how to fix it?
Thanks in advance.
Could you share the code?
I’ve also found that sometimes Xcode needs a restart and errors go away if I do that.
Here is the code:
import SwiftUI
let mainColor = Color(red:20/255, green: 28/255, blue: 58/255)
let accentColor = Color(red: 48/255, green: 105/255, blue: 240/255)
struct ContentView: View {
var body: some View {
ZStack {
mainColor.ignoresSafeArea()
VStack {
Text(“1/10”)
.font(.callout)
.multilineTextAlignment(.leading)
.padding()
Text(“How many carbons are needed to form a ring structured compound?”)
.font(.largeTitle)
.bold()
.multilineTextAlignment(.leading)
Spacer()
HStack {
Button(action: {
print(“Tapped on Choice 1”)
}, label: {
Text(“5Cs”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 2”)
}, label: {
Text(“3Cs”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 3”)
}, label: {
Text(“7Cs”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
Button(action: {
print(“Tapped on Choice 4”)
}, label: {
Text(“6Cs”)
.font(.body)
.bold()
.multilineTextAlignment(.center)
.padding()
.border(accentColor, width: 4)
})
}
}
}
.foregroundColor(.white)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I have tried restarting the app, but the error doesn’t seem to go away.
I think the error is coming from:
.border(accentColor, width: 4)
When I changed it to .border(.white, width: 4)
the error went away. Not sure why that is though!
Okay great. Thanks a lot for your help.
.white seems to solve the problem.