Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

reddavis/InnerShadow

Repository files navigation

Inner Shadow Yo!

i saw this tweet.

and was like...cool...

so i threw this into a lil SwiftUI package so i could play around with it and here it is.

Note

This uses a private property on CALayer, should be fine, might not.

Requirements

  • iOS 18.0+

Installation

Swift Package Manager

In Xcode:

  1. click Project.
  2. click Package Dependencies.
  3. click +.
  4. enter package URL: https://github.com/reddavis/InnerShadow.
  5. add InnerShadow to your app target.

Usage

VStack(spacing: 20) {
 RoundedRectangle(cornerRadius: 16)
 .fill(.white)
 .frame(width: 100, height: 100)
 .innerShadow(radius: 10, x: 0, y: 6, shape: .rect(cornerRadius: 24))
 Capsule()
 .stroke(.black.opacity(0.15), lineWidth: 1)
 .fill(.white)
 .frame(width: 100, height: 50)
 .innerShadow(radius: 10, x: 0, y: 6, shape: .capsule)
 Circle()
 .fill(.white)
 .frame(width: 100, height: 100)
 .innerShadow(radius: 10, x: 0, y: 6, shape: .circle)
}

there are some standard predefined shapes but if you have a weird ass shape, you can use InnerShadowShape.

which is just:

public struct InnerShadowShape: Shape {
 public var path: @Sendable (CGRect) -> Path
 public func path(in rect: CGRect) -> Path {
 path(rect)
 }
}

About

Inner shadows with SwiftUI

Topics

Resources

License

Stars

Watchers

Forks

Languages

AltStyle によって変換されたページ (->オリジナル) /