Created
May 15, 2020 06:18
-
-
Save agelessman/7611a357db4be4764db0ff9dd783b61f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
ZStack { | |
LinearGradient(Color.darkStart, Color.darkEnd) | |
Button(action: { | |
}) { | |
Image(systemName: "heart.fill") | |
.foregroundColor(.white) | |
} | |
.buttonStyle(DarkButtonStyle()) | |
} | |
.edgesIgnoringSafeArea(.all) | |
} | |
} | |
extension Color { | |
static let offWhite = Color(red: 225.0 / 255.0, | |
green: 225.0 / 255.0, | |
blue: 235.0 / 255.0) | |
static let darkStart = Color(red: 50 / 255, green: 60 / 255, blue: 65 / 255) | |
static let darkEnd = Color(red: 25 / 255, green: 25 / 255, blue: 30 / 255) | |
} | |
extension LinearGradient { | |
init(_ colors: Color...) { | |
self.init(gradient: Gradient(colors: colors), startPoint: .topLeading, endPoint: .bottomTrailing) | |
} | |
} | |
struct DarkBackground<S: Shape>: View { | |
var isHighlighted: Bool | |
var shape: S | |
var body: some View { | |
ZStack { | |
if isHighlighted { | |
shape | |
.fill(LinearGradient(Color.darkEnd, Color.darkStart)) | |
.overlay(shape.stroke(LinearGradient(Color.darkStart, Color.darkEnd), lineWidth: 4)) | |
.shadow(color: Color.darkStart, radius: 10, x: 5, y: 5) | |
.shadow(color: Color.darkEnd, radius: 10, x: -5, y: -5) | |
} else { | |
shape | |
.fill(LinearGradient(Color.darkStart, Color.darkEnd)) | |
.overlay(shape.stroke(Color.darkEnd, lineWidth: 4)) | |
.shadow(color: Color.darkStart, radius: 10, x: -10, y: -10) | |
.shadow(color: Color.darkEnd, radius: 10, x: 10, y: 10) | |
} | |
} | |
} | |
} | |
struct DarkButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.padding(30) | |
.background( | |
DarkBackground(isHighlighted: configuration.isPressed, shape: Circle()) | |
) | |
.animation(nil) | |
} | |
} | |
struct SimpleButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.padding(30) | |
.background( | |
Group { | |
if configuration.isPressed { | |
Circle() | |
.fill(Color.offWhite) | |
.overlay( | |
Circle() | |
.stroke(Color.gray, lineWidth: 4) | |
.blur(radius: 4) | |
.offset(x: 2, y: 2) | |
.mask(Circle().fill(LinearGradient(.black, .clear))) | |
) | |
.overlay( | |
Circle() | |
.stroke(Color.white, lineWidth: 8) | |
.blur(radius: 4) | |
.offset(x: -2, y: -2) | |
.mask(Circle().fill(LinearGradient(.clear, .black))) | |
) | |
} else { | |
Circle() | |
.fill(Color.offWhite) | |
.shadow(color:Color.black.opacity(0.2), radius: 10, x: 10, y: 10) | |
.shadow(color:Color.white.opacity(0.7), radius: 10, x: -5, y: -5) | |
} | |
} | |
) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment