Skip to content

Instantly share code, notes, and snippets.

@1mash0
Created December 19, 2023 18:03
Show Gist options
  • Save 1mash0/aa207bee445061633fe63ea4089f2e77 to your computer and use it in GitHub Desktop.
Save 1mash0/aa207bee445061633fe63ea4089f2e77 to your computer and use it in GitHub Desktop.
タップした時に縮小するスケールボタン
import PlaygroundSupport
import SwiftUI
import SceneKit
struct ContentView: View {
@State var isFavorite = false
var body: some View {
VStack(spacing: 30) {
HStack(spacing: 20) {
Button {
print("tap")
} label: {
Text("Back")
.font(.body)
.foregroundColor(.cyan)
.frame(width: 150, height: 60)
.background(.clear) // .whiteにすれば下記の.contentShapeは不要
.overlay(
RoundedRectangle(cornerRadius: 30)
.stroke(.cyan, lineWidth: 3)
)
.contentShape(RoundedRectangle(cornerRadius: 30))
}
.buttonStyle(ScaleButtonStyle())
Button {
print("tap")
} label: {
Text("Next")
.font(.body)
.foregroundColor(.white)
.frame(width: 150, height: 60)
.background(.cyan)
.cornerRadius(30)
}
.buttonStyle(ScaleButtonStyle())
}
Button {
print("tap")
isFavorite.toggle()
} label: {
Image(systemName: isFavorite ? "heart.fill": "heart")
.resizable()
.renderingMode(.original)
.frame(width: 50, height: 50)
}
.buttonStyle(ScaleButtonStyle())
}
}
}
struct ScaleButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.9 : 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment