I would like to understand why am I having issue with the background()
?
Instance method 'background(_:alignment:)' requires that 'UIColor' conform to 'View'
var body: some View {
Button("MY BUTTON") {
print("the action")
}
.padding()
.background(Color.black)
.foregroundColor(.white)
.clipShape(Capsule())
}
UPDATE
Get same thing with this:
Thanks
You probably created another struct/class called Color
. Xcode syntax highlighting is different for Color.black
- this suggests you're not using the SwiftUI Color
.
Try this calling it explicitly:
.background(SwiftUI.Color.black)
Had the same problem, none of the answers helped me either. What finally worked for me was defining (initialising) the color each time.
Text("Hello World").padding.background(Color.init(UIColor(red: 0, green:0, blue:0, alpha: 1)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With