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 | struct ContentView : View { @State private var isPressed : Bool = false var body : some View { Button ( action : { self . isPressed . toggle () }, label : { VStack { Text ( "Hello" ) }. neumorphic ( isPressed : $ isPressed , bgColor : . orange ) }) . frame ( maxWidth : . infinity , maxHeight : . infinity ) . background ( Color . orange ) . edgesIgnoringSafeArea (. all ) } } struct Neumorphic : ViewModifier { var bgColor : Color @Binding var isPressed : Bool func body ( content : Content ) - > some View { content . padding ( 20 ) . background ( ZStack { RoundedRectangle ( cornerRadius : 10 , style : . continuous ) . shadow ( color : . white , radius : self . isPressed ? 7 : 10 , x : self . isPressed ? - 5 : - 15 , y : self . isPressed ? - 5 : - 15 ) . shadow ( color : . black , radius : self . isPressed ? 7 : 10 , x : self . isPressed ? 5 : 15 , y : self . isPressed ? 5 : 15 ) . blendMode (. overlay ) RoundedRectangle ( cornerRadius : 10 , style : . continuous ) . fill ( bgColor ) } ) . scaleEffect ( self . isPressed ? 0.95 : 1 ) . foregroundColor (. primary ) . animation (. spring ()) } } extension View { func neumorphic ( isPressed : Binding < Bool > , bgColor : Color ) - > some View { self . modifier ( Neumorphic ( bgColor : bgColor , isPressed : isPressed )) } } |