Customizable blur effect view with blur radius, tint color and tint color alpha.
CustomBlurEffectView is a customizable blur effect view with blur radius, tint color and tint color alpha. This library uses the UIVisualEffectView to generate the blur.
- iOS 9.0+
- Xcode 9.0+
- Swift 5
Add an instance of CustomBlurEffectView to your view.
import CustomBlurEffectView
let customBlurEffectView = CustomBlurEffectView(
radius: 20, // Set blur radius value. Defaults to `10` (CGFloat)
color: .cyan, // Set tint color value. Defaults to `nil` (UIColor?)
colorAlpha: 0.4 // Set tint color alpha value. Defaults to `0.8` (CGFloat)
)
customBlurEffectView.frame = CGRect(x: 0, y: 0, width: 300, height: 300)
addSubview(customBlurEffectView)
Either you can configure the view different way.
let customBlurEffectView = CustomBlurEffectView()
customBlurEffectView.frame = CGRect(x: 0, y: 0, width: 300, height: 300)
customBlurEffectView.blurRadius = 20
customBlurEffectView.colorTint = .cyan
customBlurEffectView.colorTintAlpha = 0.4
addSubview(customBlurEffectView)
CustomBlurEffectView is inherited from UIView, and UIVisualEffectView is a subview of CustomBlurEffectView. To get UIVisualEffectView layer directly you can use blurLayer
property:
let customBlurEffectView = CustomBlurEffectView()
let layer = customBlurEffectView.blurLayer
For more examples, take a look at the example project.
In Xcode, select File ▸ Swift Packages ▸ Add Package Dependency…. Select target. Copy the following and paste into the combined search box:
https://github.com/perfectdim/CustomBlurEffectView.git
Click Next. Choose Package Options screen with Version selected under Rules and Up to next Major and 1.0.0 selected in dropdowns. Click Next.
Xcode downloads the code from GitHub. Click Finish.
In your Package.swift:
let package = Package(
name: "Example",
dependencies: [
.package(url: "https://github.com/perfectdim/CustomBlurEffectView.git", from: "0.0.1")
],
targets: [
.target(name: "Example", dependencies: ["CustomBlurEffectView"])
]
)
Note that there’s now a Swift Package Dependencies section in the Project Navigator on the left and a Swift Packages tab in the Project settings.
- Download and drop
CustomBlurEffectView.swift
,CustomBlurEffect.swift
,UIVisualEffect+effectSettings.swift
in to your project. - Done!
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
CustomBlurEffectView utilizes a private UIKit API to do its magic. Use caution, submitting this code to the App Store adds the risk of being rejected!
https://github.com/efremidze/VisualEffectView
CustomBlurEffectView is available under the MIT license. See the LICENSE file for more info.