https://github.com/1998code/SwiftGlass
Glassy Everything, even Old Devices. [ AI Assistant available below ]
https://github.com/1998code/SwiftGlass
apple glass ios ipados macos swift swiftglass swiftui tvos visionos watchos
Last synced: 2 days ago
JSON representation
Glassy Everything, even Old Devices. [ AI Assistant available below ]
- Host: GitHub
- URL: https://github.com/1998code/SwiftGlass
- Owner: 1998code
- License: mit
- Created: 2025-04-20T06:22:59.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2025-04-22T10:06:16.000Z (9 days ago)
- Last Synced: 2025-04-23T07:38:15.587Z (8 days ago)
- Topics: apple, glass, ios, ipados, macos, swift, swiftglass, swiftui, tvos, visionos, watchos
- Language: Swift
- Homepage: https://shareby.vercel.app/4zel3m
- Size: 112 KB
- Stars: 262
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# SwiftGlass





## 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
🧩 **SwiftUI integration**: Simple ViewModifier implementation## Gallery
|
|  |  |
| -- | -- | -- |
| iOS | watchOS I | watchOS II ||  |  |
| -- | -- |
| macOS (Dark) I | macOS (Dark) II ||  |  |
| -- | -- |
| tvOS I | tvOS II ||  |  |
| -- | -- |
| 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 |
## 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
```
> Or you may add it manually as follows
```swift
dependencies: [
.package(url: "https://github.com/1998code/SwiftGlass.git", from: "1.0.0")
]
```## Usage
### Basic Usage (View / Button / Anywhere)
```swift
import SwiftUI
import SwiftGlassstruct ContentView: View {
var body: some View {
Text("Hello, Glass!")
.padding(40)
.glass() // Use default glass effect
}
}
```### Custom Glass Effect
```swift
VStack {
Text("Custom Glass")
Image(systemName: "sparkles")
}
.padding(30)
.glass(
radius: 20,
color: .blue,
material: .regularMaterial,
gradientOpacity: 0.7,
shadowColor: .blue,
shadowRadius: 10
)
```## 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 |
| `color` | `Color` | `.white` | Base color for gradient and highlights |
| `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` | `.white` | 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 |## Platform-Specific Notes
- **visionOS**: On visionOS, SwiftGlass uses the native `.glassBackgroundEffect()` for optimal rendering and system integration
- **Other platforms**: A custom implementation combines materials, gradients, and shadows to achieve a similar effect## 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 | [繁中](/README/README_tc.md) / [简中](/README/README_zh.md) / [粵語](/README/README_hc.md) | [日本語](/README/README_ja.md) | [한국어](/README/README_ko.md)
Please feel free to open a pull request and add new language(s) or fix any typos/mistakes.