Skip to content

Instantly share code, notes, and snippets.

@jayesh15111988
Created May 6, 2022 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayesh15111988/fa873576175564aae47eb569831b7e2d to your computer and use it in GitHub Desktop.
Save jayesh15111988/fa873576175564aae47eb569831b7e2d to your computer and use it in GitHub Desktop.
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