Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding Shadow View in SwiftUI
import SwiftUI
struct ShadowView: View {
let xOffset: CGFloat
let yOffset: CGFloat
var body: some View {
Text("SwiftUI is Awesome").padding().background(
Rectangle()
.fill(Color.white)
.cornerRadius(12)
.shadow(
color: Color.gray.opacity(0.7),
radius: 8,
x: xOffset,
y: yOffset
)
)
}
}
struct ShadowView_Previews: PreviewProvider {
static var previews: some View {
VStack(spacing: 16) {
ShadowView(xOffset: 0, yOffset: 0)
ShadowView(xOffset: -8, yOffset: 0)
ShadowView(xOffset: 8, yOffset: 0)
ShadowView(xOffset: 0, yOffset: -8)
ShadowView(xOffset: 0, yOffset: 8)
ShadowView(xOffset: -8, yOffset: -8)
ShadowView(xOffset: 8, yOffset: -8)
ShadowView(xOffset: -8, yOffset: 8)
ShadowView(xOffset: 8, yOffset: 8)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment