SwiftUI: Create Inner shadow and shadow using SwiftUI

ODENZA
Jan 10, 2021

In this article, I will show you how to implement the shadow object using SwiftUI. I would like to use ViewModifier for my project.

struct ShadowModifier: ViewModifier {  func body(content: Content) -> some View {    content
.shadow(color: Color("lightShadow"), radius: 8, x: -8, y: -8)
.shadow(color: Color("darkShadow"), radius: 8, x: 8, y: 8)
}}

Inner shadow

struct InnerShadowModifier: ViewModifier {@State var radius: CGFloat = 10func body(content: Content) -> some View {content.overlay(
RoundedRectangle(cornerRadius: radius)
.stroke(Color("bgColor"), lineWidth: 4)
.shadow(color: Color("darkShadow"), radius: 4, x: 5, y: 5)
.clipShape(RoundedRectangle(cornerRadius: radius))
.shadow(color: Color("lightShadow"), radius: 4, x: -5, y: -5)
.clipShape(RoundedRectangle(cornerRadius: radius)
)}}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

ODENZA
ODENZA

No responses yet

Write a response