I got this button now:
When it’s pressed, I want the ‘background’ to be removed, like this:
How would I do that? I can not get it to work. I am now adding the background by using a ZStack
which is also not that nice because I need to initialize the Button
twice.
This is a reproduction path:
import Foundation
import SwiftUI
struct TestButton<V: View>: View {
@Environment(.colorScheme) var colorScheme: ColorScheme
let content: V
var foregroundStyle: Color? = nil
var body: some View {
ZStack {
Button(action: {} ) {
content
}
.padding(10)
.background(Color(red: 0, green: 0, blue: 255/255))
.applyDefaultCornerRadius()
.offset(y: 5)
Button(action: {}) {
content
}
.padding(10)
.background(Color.blue)
.applyDefaultCornerRadius()
.foregroundStyle(foregroundStyle ?? (colorScheme == .light ? Color.white : Color.black))
}
}
}
#Preview {
TestButton(content: Text(verbatim: "Test"))
}