Is it possible to inherit from a Button in SwiftUI? I tired it and I get an error every time, since Button
is expecting some kind of generic argument.
import SwiftUI
struct ButtonSubClass: Button<Label: View> {
var body: some View {
Text("Hello, World!")
}
}
XCode automatically adds the <Label: View>
part, but I don't know what it means or what I actually need to put in the braces.
I tried Button<View>
, but then I get the error Protocol type 'View' cannot conform to 'View' because only concrete types can conform to protocols
Button
is a struct, which cannot be subclassed. If you are trying to create a custom View
with Button
-like properties, but customized in some way, you can apply view modifiers or use the ButtonStyle
protocol.
If you can supply some specifics of what you are trying to accomplish, I will try to add some example code.
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