Skip to content

Commit

Permalink
doc: Customizing Button with ButtonStyle transforming-views/demo19/RE…
Browse files Browse the repository at this point in the history
…ADME.md (#43)
  • Loading branch information
zhu-hongwei authored Jul 18, 2023
1 parent 418d0ef commit 63de22a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion example/transforming-views/demo19/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,30 @@ struct ContentView: View {
.buttonStyle(BlueButton())
}
}
```
```
我们传递的按钮配置包括按钮当前是否被按下,因此我们可以使用它来调整按钮。

例如,我们可以创建第二种样式,使按钮在按下时变大:

```swift
struct GrowingButton: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(.blue)
.foregroundStyle(.white)
.clipShape(Capsule())
.scaleEffect(configuration.isPressed ? 1.2 : 1)
.animation(.easeOut(duration: 0.2), value: configuration.isPressed)
}
}

struct ContentView: View {
var body: some View {
Button("Press Me") {
print("Button pressed!")
}
.buttonStyle(GrowingButton())
}
}
```

0 comments on commit 63de22a

Please sign in to comment.