File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
example/transforming-views/demo19 Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -37,4 +37,30 @@ struct ContentView: View {
37
37
.buttonStyle (BlueButton ())
38
38
}
39
39
}
40
- ```
40
+ ```
41
+ 我们传递的按钮配置包括按钮当前是否被按下,因此我们可以使用它来调整按钮。
42
+
43
+ 例如,我们可以创建第二种样式,使按钮在按下时变大:
44
+
45
+ ``` swift
46
+ struct GrowingButton : ButtonStyle {
47
+ func makeBody (configuration : Configuration) -> some View {
48
+ configuration.label
49
+ .padding ()
50
+ .background (.blue )
51
+ .foregroundStyle (.white )
52
+ .clipShape (Capsule ())
53
+ .scaleEffect (configuration.isPressed ? 1.2 : 1 )
54
+ .animation (.easeOut (duration : 0.2 ), value : configuration.isPressed )
55
+ }
56
+ }
57
+
58
+ struct ContentView : View {
59
+ var body: some View {
60
+ Button (" Press Me" ) {
61
+ print (" Button pressed!" )
62
+ }
63
+ .buttonStyle (GrowingButton ())
64
+ }
65
+ }
66
+ ```
You can’t perform that action at this time.
0 commit comments