Glassmorphism is a design style using a background blur effect, which makes the view look like a floating translucent glass.
Use Swift Package Manager by adding following line to Package.swift
:
dependencies: [
.package(url: "https://github.com/Chaehui-Seo/CHGlassmorphismView.git", from: "0.0.2")
]
METHOD #1
Import CHGlassmorphismView
module to your controller. Now, you can create glassmorphism view programmatically like code below.
import CHGlassmorphismView
let glassmorphismView = CHGlassmorphismView()
METHOD #2
Or make existing UIView as glassmorphism view by changing the Custom Class to CHGlassmorphismView
// MARK: - [Theme]
glassmorphismView.setTheme(theme: .light) // choose theme .light or .dark
Light theme | dark theme |
---|---|
![]() |
![]() |
// MARK: - [Blur Density]
glassmorphismView.changeBlurDensity(with: 0.5) // value from 0 to 1 is available
Light theme | dark theme |
---|---|
![]() |
![]() |
// MARK: - [Corner Radius]
glassmorphismView.setCornerRadius(30) // change cornerRadius as you want (default value is 20)
// MARK: - [Shadow Radius (Shadow Spread)]
glassmorphismView.setDistance(30) // change shadowRadius(shadow spread) that makes a sense of distance (default value is 20)
You can run SampleApp Project located in SampleApp
folder.
All the functions that provided by the package are testable through the SampleApp project.
Be aware that any views underneath blurred view got affected by glassmorphism effect. That means if some views are inserted before blurred view, it would not be visible as expected. Do not insert any views at 0 if you don’t want the elements to be dimmed
// DO ⭕️
glassmorphismView.addSubview(yourOwnView)
// DO NOT ❌
glassmorphismView.insertSubview(yourOwnView, at: 0)
link |
Stars: 11 |
Last commit: 3 days ago |
[FEATURE] Provide UIStoryboard preview [FEATURE] Add setDistance method than can control shadowRadius [CHANGED] Improve dark mode appearance [CHANGED] Improve cornerRadius setting by separating with shadowRadius
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics