-
Notifications
You must be signed in to change notification settings - Fork 0
/
BindingWrapper.swift
52 lines (44 loc) · 1.21 KB
/
BindingWrapper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import SwiftUI
struct BindingWrapper: View {
@State var backgroundColor: Color = .green
@State var title: String = "Informative Button"
var body: some View {
ZStack {
backgroundColor.edgesIgnoringSafeArea(.all)
VStack {
Text(title)
.font(.title)
.foregroundStyle(.white)
ButtonView(
backgroundColor: $backgroundColor,
title: $title
)
}
}
}
}
struct ButtonView: View {
@Binding var backgroundColor: Color
@State var buttonColor: Color = .blue
@Binding var title: String
var body: some View {
Button(
action: {
backgroundColor = .yellow
buttonColor = .red
title = "Destructive Button"
},
label: {
Text("Button")
.foregroundStyle(.white)
.padding()
.padding(.horizontal)
.background(buttonColor)
.cornerRadius(10)
}
)
}
}
#Preview {
BindingWrapper()
}