Skip to content

1998code/SwiftGlass

GK

SwiftGlass

StableBetaBuild TestSwift Version

PlatformsLicense

SwiftGlass@3x

Features

🔄 Cross-platform: Works on iOS, macOS, watchOS, tvOS, and visionOS
Native visionOS support: Uses native glass effect on visionOS
🎨 Highly customizable: Adjust colors, materials, shadows, and more
🔷 Multiple shapes: Support for rounded rectangle, circle, and capsule shapes
🧩 SwiftUI integration: Simple ViewModifier implementation

Gallery

Screenshot 2025-04-20 at 4 16 55 PMimageimage
iOSwatchOS IwatchOS II
imageimage
macOS (Dark) ImacOS (Dark) II
imageimage
tvOS ItvOS II
imageimage
visionOSiPadOS

Tested Platforms and Environment

PlatformiOSmacOSwatchOStvOSvisionOS
Version15.0+14.0+10.0+15.0+1.0+
Xcode LatestMinimumSVT
16.315.05.9

image

Project Demo (Quick Starter)

Open /Demo/Demo.xcodeproj 

⚠️ To prevent resolving failed, please rename the root folder from SwiftGlass-xxx to SwiftGlass

Installation (on your project)

Swift Package Manager

Add SwiftGlass to your project through Swift Package Manager

PROJECT > Package Dependencies > +

https://github.com/1998code/SwiftGlass.git 
Screenshot 2025-04-20 at 4 29 46 PM

Or you may add it manually as follows

dependencies:[.package(url:"https://github.com/1998code/SwiftGlass.git", from:"1.0.0")]

Usage

Basic Usage (View / Button / Anywhere)

Screenshot 2025-04-20 at 2 41 51 PM
import SwiftUI import SwiftGlass structContentView:View{varbody:someView{Text("Hello, Glass!").padding(40).glass() // Use default glass effect }}

Custom Glass Effect

Screenshot 2025-04-20 at 2 40 11 PM
VStack{Text("Custom Glass")Image(systemName:"sparkles")}.padding(30).glass( radius:20, color:.blue, material:.regularMaterial, gradientOpacity:0.7, shadowColor:.blue, shadowRadius:10)

Different Shapes

SwiftGlass supports multiple shapes for the glass effect:

// Circle shape Image(systemName:"heart.fill").frame(width:100, height:100).glass(shape:.circle, color:.pink) // Capsule shape (pill-shaped) Button("Play Music"){}.padding().glass(shape:.capsule, color:.blue) // Rounded rectangle (default) Text("Hello").padding().glass(radius:20, shape:.roundedRectangle(radius:20))

Customization

SwiftGlass offers extensive customization options:

ParameterTypeDefaultDescription
displayMode.always or .automatic.alwaysControls when the effect is displayed
radiusCGFloat32Corner radius of the glass effect (for rounded rectangle)
shape.roundedRectangle(radius:), .circle, or .capsule.roundedRectangle(radius: radius)Shape of the glass effect
colorColorSystem background colorBase color for gradient and highlights
colorOpacityDouble0.1Opacity level for the base color
materialMaterial.ultraThinMaterialSwiftUI material style
gradientOpacityDouble0.5Opacity level for the gradient overlay
gradientStyle.normal or .reverted.normalDirection style of the gradient
strokeWidthCGFloat1.5Width of the border stroke
shadowColorColorSystem background colorColor of the drop shadow
shadowOpacityDouble0.5Opacity level for the shadow
shadowRadiusCGFloat?nilBlur radius for the shadow
shadowXCGFloat0Horizontal offset of the shadow
shadowYCGFloat5Vertical offset of the shadow
isInToolbarBoolfalseOptimizes rendering when used in toolbars (iOS 26+)

Platform-Specific Notes

  • visionOS: On visionOS, SwiftGlass uses the native .glassBackgroundEffect() for optimal rendering and system integration
  • iOS 26+ / macOS 26+: Uses native .glassEffect() API with enhanced toolbar support
  • Other platforms: A custom implementation combines materials, gradients, and shadows to achieve a similar effect
  • Cross-platform colors: Shadow and base colors automatically adapt to system background colors on each platform

Contributing

Contributions to SwiftGlass are welcome!

  • To report bugs or request features, please open an issue on GitHub
  • When submitting a pull request, please follow the coding style of the project

License

MIT. Read the LICENSE file for details.

Translation

This doc is also available in:

English | 繁中 / 简中 / 粵語 | 日本語 | 한국어

Please feel free to open a pull request and add new language(s) or fix any typos/mistakes.

Supported By



Ask DeepWiki

About

Glassy Everything, even Old Devices. [ AI Assistant available below ]

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •  

Languages