Dynamic blur background view with tint color (UIVisualEffectView subclass) 📱

Overview

VisualEffectView

Build Status Carthage compatible Language Version License

VisualEffectView is a blur effect library with tint color support. This library uses the UIVisualEffectView to generate the blur.

Demo GIF

Demo Video

$ pod try VisualEffectView

Requirements

  • iOS 9.0+
  • Xcode 9.0+
  • Swift 5 (VisualEffectView 4.x), Swift 4 (VisualEffectView 3.x), Swift 3 (VisualEffectView 2.x), Swift 2 (VisualEffectView 1.x)

Usage

Add an instance of VisualEffectView to your view.

import VisualEffectView

let visualEffectView = VisualEffectView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))

// Configure the view with tint color, blur radius, etc
visualEffectView.colorTint = .redColor()
visualEffectView.colorTintAlpha = 0.2
visualEffectView.blurRadius = 10
visualEffectView.scale = 1

addSubview(visualEffectView)

Depending on the desired effect, the effect may affect content layered behind the view or content added to the visual effect view’s contentView. After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself. Refer to the UIVisualEffectView for more info.

For more examples, take a look at the example project.

Customization

var colorTint: UIColor // tint color. default is nil
var colorTintAlpha: CGFloat // tint color alpha. default is 0
var blurRadius: CGFloat // blur radius. default is 0
var scale: CGFloat // scale factor. default is 1

If you want colorTintAlpha to be different from 0, make sure you always set it right after setting the colorTint or it may not be applied as expected. You also have to make sure you don't set colorTintAlpha if colorTint is nil.

Storyboard Support

Works great with storyboards and xibs.

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "VisualEffectView"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/VisualEffectView"

Manually

  1. Download and drop VisualEffectView.swift in your project.
  2. Congratulations!

Communication

  • 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.

Disclaimer

VisualEffectView utilizes a private UIKit API to do its magic. Use caution, submitting this code to the App Store adds the risk of being rejected!

Credits

https://github.com/collinhundley/APCustomBlurView

License

VisualEffectView is available under the MIT license. See the LICENSE file for more info.

Comments
  • Some problem with saturation

    Some problem with saturation

    New Issue Checklist

    Issue Description

    I'm use: blurRadius = 5 colorTintAlpha = nil (or .clear) scale = 1

    result:

    Environment

    • iOS Version: 14.0
    • Device(s): iPhone 10 XMax
    opened by MrGrig 8
  • Fix iOS 16 missing background color

    Fix iOS 16 missing background color

    Checklist

    Motivation and Context

    Description

    Background color for iOS 16 is not changing. This fix solves the issue

    opened by KirillMagerya 3
  • updated to swift 3

    updated to swift 3

    This code should be merged to a new branch named swift-3. @efremidze Please create a new branch and I will create the PR again.

    This should not be merged in master as of now, since Xcode 8 is still in beta mode.

    opened by RishabhTayal 3
  • Tag & Release 2.0.3

    Tag & Release 2.0.3

    This commit also makes the pod spec infer the version from the Xcode project thus reducing duplication.

    I meddled with the xcodeproj a little to make sure the version is not duplicated around and is set in all the places it should be.

    opened by mxcl 2
  • Screen is shivering when i added this in tableview with multiple cell.Please suggest how can i fix it?

    Screen is shivering when i added this in tableview with multiple cell.Please suggest how can i fix it?

    New Issue Checklist

    Issue Description

    Environment

    • iOS Version: [INSERT iOS VERSION HERE]
    • Device(s): [INSERT DEVICE(S) HERE]
    opened by iAmita 1
  • iOS 8.x crash

    iOS 8.x crash

    Hello,

    I'm using VisualEffectView to find a custom UIVisualEffectView. When I read ReadMe, iOS 8.0 + is actually crashing when iOS 8.x is run.

    private let blurEffect = (NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type).init()
    

    fatal error: unexpectedly found nil while unwrapping an Optional value

    it's probably an iOS9+ API

    opened by Kofktu 1
  • height and width Constraints not working

    height and width Constraints not working

    `let effect = VisualEffectView()//VisualEffectView(frame: CGRect(x: 0, y: 0, width: 600, height: 600)) effect.translatesAutoresizingMaskIntoConstraints = false effect.colorTint = .red effect.colorTintAlpha = 0.2 effect.blurRadius = 10 effect.scale = 1

        view.addSubview(effect)
        effect.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0).isActive = true
        effect.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0).isActive = true
    

    `

    opened by ghost 1
  • Fixed force cast crash on iOS 13-

    Fixed force cast crash on iOS 13-

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Fixes an issue from #32 Some additional work may be needed to prevent us having to wrap calls to colorTintAlpha with if colorTint != nil conditions but that's another topic.

    Description

    func _value<T>(forKey key: Key) -> T? now returns an optional.

    opened by amaurydavid 0
  • Crashes on iOS 13 when tintColor is nil

    Crashes on iOS 13 when tintColor is nil

    Hello, I wanted to try out the latest version (4.1.1) with the iOS 14 fix but now I've got some crashes on iOS 13.5.

    func newVisualEffectView(tint: UIColor? = nil) -> VisualEffectView {
            let view = VisualEffectView(frame: self.view.frame)
            view.colorTint = tint
            view.colorTintAlpha = 0.92
            view.blurRadius = 7
            view.scale = 1
            return view
    }
    

    This raises a runtime error when tint is nil:

    func _setValue<T>(_ value: T, forKey key: Key) {
            blurEffect.setValue(value, forKeyPath: key.rawValue)
            if #available(iOS 14, *) {} else {
                self.effect = blurEffect // <- -[NSNull _backgroundColorIgnoringHighContrast]: unrecognized selector sent to instance 0x7fff8062d9d0
            }
    }
    

    So I've added a check to not set the colorTintAlpha if there was no tintColor:

    func newVisualEffectView(tint: UIColor? = nil) -> VisualEffectView {
            let view = VisualEffectView(frame: self.view.frame)
            view.colorTint = tint
            if view.colorTint != nil {
                view.colorTintAlpha = 0.92
            }
            view.blurRadius = 7
            view.scale = 1
            return view
    }
    

    This raises another runtime error when trying to access the tintColor from the new condition:

    func _value<T>(forKey key: Key) -> T {
            return blurEffect.value(forKeyPath: key.rawValue) as! T // <- Could not cast value of type 'NSNull' (0x7fff87a92380) to 'UIColor' (0x7fff897eb788).
    }
    
    opened by amaurydavid 0
  • iOS 14 Support (v4.1.0)

    iOS 14 Support (v4.1.0)

    Due to changes in iOS 14 private APIs, I've updated the library to use a workaround discovered by @unboxme. This PR replicates changes from Blurberry and fixes #23. The changes are backwards compatible and the framework API is unchanged.

    opened by efremidze 0
  • Swift 5.0

    Swift 5.0

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Description

    • Added Swift 5.0 Support
    opened by efremidze 0
  • Tint color or blurRadius issues  with iOS 16

    Tint color or blurRadius issues with iOS 16

    IOS 16 was recently updated, The same code shows the result, which is very different from what it was before iOS 16, Below is the 16 and 16 before the rendering
    please help me to solve the problem

    opened by ZexiFangkong 3
  • Redundant blue half-transparent overlay on iOS 14

    Redundant blue half-transparent overlay on iOS 14

    Changing colorTint = .clear not solves the problem. It seems like colorTint had effect on _UIVisualEffectSubview, but blue overlay is in _UIVisualEffectBackdropView.

    I was expecting that will find a solution here, but now think that only I have this problem.

    iPhone 11 – 14 0 2020-09-24 09-27-03
    opened by Art3mS1d 1
  • is not working in iOS 14

    is not working in iOS 14

    it is working if you add this

    func setValue( value: T, forKey key: Key) { blurEffect.setValue(value, forKeyPath: key.rawValue) if #available(iOS 14, *) { } else { self.effect = blurEffect } }

    opened by MehmetDenizYalcin 8
  • Blur effect apply on Status Bar

    Blur effect apply on Status Bar

    Is there any way to apply Blur effect on Status Bar view.

    Please note that This is not the Bug BUT in iPhone blue effect apply on whole screen area include status bar Real time and battery icon too.

    Thanks in Advance.

    opened by suraj-ios 0
Owner
Lasha Efremidze
#iOS Engineer @amzn @EdisonJunior (Ring). Previously @eBay @stubhub @calaborate (Klutch). Open source enthusiast.
Lasha Efremidze
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Wilson Ding 334 Jan 7, 2023
UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

Mohsan Khan 29 Sep 9, 2022
Dynamic textview with auto-resizing height & width that is also movable/draggable.

MarkupTextView Dynamic textview with auto-resizing height & width that is also movable/draggable. Requirements iOS 13 or above Installation MarkupText

Seok Kwun Park 2 Nov 17, 2022
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.

KDInteractiveNavigationController Features ✨ UINavigationController interactive with UINavigationBar hidden or show Hide all UINavigationController ba

Kingiol 154 Dec 3, 2022
A UITextView subclass that adds support for multiline placeholder written in Swift.

KMPlaceholderTextView A UITextView subclass that adds support for multiline placeholder written in Swift. Usage You can set the value of the placehold

Zhouqi Mo 794 Jan 7, 2023
UIViewController subclass to beautifully present news articles and blog posts.

LMArticleViewController This framework allows you to create Apple News-inspired UIViewControllers with ease. It is heavily inspired by MRArticleViewCo

Luca Mozzarelli 7 Feb 3, 2022
A UIControl subclass that makes it easy to create empty states.

AZEmptyState Making empty state simple. Screenshots Installation Cocoa Pods: pod 'AZEmptyState' Manual: Simply drag and drop the Sources folder to you

Antonio Zaitoun 88 Oct 2, 2022
IHTypeWriterLabel - A simple, UILabel subclass which poulates itself as if being typed

IHTypeWriterLabel A simple, UILabel subclass which poulates itself as if being typed. HighLights Written purely in SWIFT. Very simple and lightweight.

Md Ibrahim Hassan 24 May 7, 2019
A customizable color picker for iOS in Swift

IGColorPicker is a fantastic color picker ?? written in Swift. Table of Contents Documentation Colors Style Other features Installation Example Gettin

iGenius 272 Dec 17, 2022
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jogendra 772 Dec 28, 2022
Confetti View lets you create a magnificent confetti view in your app

ConfettiView Confetti View lets you create a magnificent confetti view in your app. This was inspired by House Party app's login screen. Written in Sw

Or Ron 234 Nov 22, 2022
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
Play BreakOut while loading - A playable pull to refresh view using SpriteKit

BreakOutToRefresh Play BreakOut while loading - A playable pull to refresh view using SpriteKit BreakOutToRefresh uses SpriteKit to add a playable min

Dominik Hauser 2.5k Jan 5, 2023
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.

Elissa Attach a local notification to any UIView to reveal additional user guidance. Usage Example Per default, Elissa will try to align to the center

null 169 Aug 14, 2022
Cool Animated music indicator view written in Swift

Cool Animated music indicator view written in Swift. ESTMusicIndicator is an implementation of NAKPlaybackIndicatorView in Swift for iOS 8. 本人著作的书籍《La

Aufree 465 Nov 28, 2022
A child view controller framework that makes setting up your parent controllers as easy as pie.

Description Family is a child view controller framework that makes setting up your parent controllers as easy as pie. With a simple yet powerful publi

Christoffer Winterkvist 246 Dec 28, 2022
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 467 Dec 5, 2022
A container view that responds to scrolling of UIScrollView

FlexibleHeader A container view that responds to scrolling of UIScrollView. normal threshold FlexibleHeaderExecutantType Getting Started Progressive I

DongHee Kang 69 May 2, 2022