1998code/SwiftGlass
Glassy Everything, even Old Devices. [ AI Assistant available below ]
Features
🔄 Cross-platform: Works on iOS, macOS, watchOS, tvOS, and visionOS<br/> ✨ Native visionOS support: Uses native glass effect on visionOS<br/> 🎨 Highly customizable: Adjust colors, materials, shadows, and more<br/> 🔷 Multiple shapes: Support for rounded rectangle, circle, and capsule shapes<br/> 🧩 SwiftUI integration: Simple ViewModifier implementation
Gallery
| <img width="421" alt="Screenshot 2025-04-20 at 4 16 55 PM" src="https://github.com/user-attachments/assets/062a85c7-6269-4aee-a9b3-b2b336f2c3b0" /> | [image] | [image] | | -- | -- | -- | | iOS | watchOS I | watchOS II |
| [image] | [image] | | -- | -- | | macOS (Dark) I | macOS (Dark) II |
| [image] | [image] | | -- | -- | | tvOS I | tvOS II |
| [image] | [image] | | -- | -- | | visionOS | iPadOS |
Tested Platforms and Environment
| Platform | iOS | macOS | watchOS | tvOS | visionOS | | -- | -- | -- | -- | -- | -- | | Version | 15.0+ | 14.0+ | 10.0+ | 15.0+ | 1.0+ |
| Xcode Latest | Minimum | SVT | | -- | -- | -- | | 16.3 | 15.0 | 5.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<img width="1248" alt="Screenshot 2025-04-20 at 4 29 46 PM" src="https://github.com/user-attachments/assets/443f3489-c8b2-4d4f-a716-0003ecab5951" />
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)
<img width="328" alt="Screenshot 2025-04-20 at 2 41 51 PM" src="https://github.com/user-attachments/assets/1c64b4a6-7e10-4ee8-8e81-a731891a10fb" />
import SwiftUI
import SwiftGlass
struct ContentView: View {
var body: some View {
Text("Hello, Glass!")
.padding(40)
.glass() // Use default glass effect
}
}Custom Glass Effect
<img width="328" alt="Screenshot 2025-04-20 at 2 40 11 PM" src="https://github.com/user-attachments/assets/0c2c234a-2c74-4262-9a54-23d62ba03815" />
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:
| Parameter | Type | Default | Description | |---|---|---|---| | displayMode | .always or .automatic | .always | Controls when the effect is displayed | | radius | CGFloat | 32 | Corner radius of the glass effect (for rounded rectangle) | | shape | .roundedRectangle(radius:), .circle, or .capsule | .roundedRectangle(radius: radius) | Shape of the glass effect | | color | Color | System background color | Base color for gradient and highlights | | colorOpacity | Double | 0.1 | Opacity level for the base color | | material | Material | .ultraThinMaterial | SwiftUI material style | | gradientOpacity | Double | 0.5 | Opacity level for the gradient overlay | | gradientStyle | .normal or .reverted | .normal | Direction style of the gradient | | strokeWidth | CGFloat | 1.5 | Width of the border stroke | | shadowColor | Color | System background color | Color of the drop shadow | | shadowOpacity | Double | 0.5 | Opacity level for the shadow | | shadowRadius | CGFloat? | nil | Blur radius for the shadow | | shadowX | CGFloat | 0 | Horizontal offset of the shadow | | shadowY | CGFloat | 5 | Vertical offset of the shadow | | isInToolbar | Bool | false | Optimizes 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
<a href="https://m.do.co/c/ce873177d9ab"> <img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px"> </a> <br/> <br/>
[[Ask DeepWiki]](https://deepwiki.com/1998code/SwiftGlass)
Package Metadata
Repository: 1998code/SwiftGlass
Homepage: https://shareby.vercel.app/4zel3m
Stars: 384
Forks: 19
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: apple, glass, ios, ipados, macos, swift, swiftglass, swiftui, tvos, visionos, watchos
README: README.md