Difference between revisions of "UIBackdropView"

From iPhone Development Wiki
Jump to: navigation, search
m (UIBackDropView -> UIBackdropView)
(Added more info.)
Line 1: Line 1:
'''_UIBackdropView''' is a private class in [[UIKit.framework]] (iOS 7.0+), which is used for the popular blur effects.
+
'''_UIBackdropView''' is a private class in [[UIKit.framework]] (iOS 7.0+), a subclass of [[UIView]], which is used for the popular blur effects.
  
 
It uses a [[CABackdropLayer]] with a [[CAFilter#gaussianBlur|gaussianBlur CAFilter]].<ref>https://twitter.com/conradev/status/380905728393117696</ref>
 
It uses a [[CABackdropLayer]] with a [[CAFilter#gaussianBlur|gaussianBlur CAFilter]].<ref>https://twitter.com/conradev/status/380905728393117696</ref>
  
== Example ==
+
To create the _UIBackdropView, you need to create its settings first. Here's all settings class available in iOS 7.0
 +
{| class="wikitable"
 +
|-
 +
! Class name
 +
! Style number
 +
! Comments/Used by
 +
|-
 +
| _UIBackdropViewSettingsBlur
 +
| 0
 +
| Common blurring
 +
|-
 +
| _UIBackdropViewSettingsUltraLight
 +
| 2010
 +
| Some alert views in Settings app & many white UIs
 +
|-
 +
| _UIBackdropViewSettingsLight
 +
| 2020
 +
|
 +
|-
 +
| _UIBackdropViewSettingsDark
 +
| 2030
 +
| iOS 7 Notification Center (?)
 +
|-
 +
| _UIBackdropViewSettingsDarkLow
 +
| 2039
 +
|
 +
|-
 +
| _UIBackdropViewSettingsColored
 +
| 2040
 +
|
 +
|-
 +
| _UIBackdropViewSettingsUltraDark
 +
| 2050
 +
|
 +
|-
 +
| _UIBackdropViewSettingsAdaptiveLight
 +
| 2060
 +
| iOS 7 Control Center
 +
|-
 +
| _UIBackdropViewSettingsSemiLight
 +
| 2070
 +
|
 +
|-
 +
| _UIBackdropViewSettingsUltraColored
 +
| 2080
 +
|
 +
|-
 +
|}
  
 +
There are 2 ways to create the settings object
 +
 +
<source lang="objc">
 +
 +
_UIBackdropViewSettings *settings = (_UIBackdropViewSettings *)[[[_UIBackdropViewSettingsSemiLight alloc] init] autorelease];
 +
 +
// or
 +
 +
_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2070];
 +
 +
</source>
 +
 +
== Creating _UIBackdropView (Blur view) object ==
 +
 +
<source lang="objc">
 +
 +
_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2060];
 +
_UIBackdropView *blurView = [[_UIBackdropView alloc] initWithFrame:CGRectZero
 +
                                              autosizesToFitSuperview:YES settings:settings];
 +
[someView addSubview:backView];
 +
[blurView release];
 +
 +
</source>
 +
 +
== Blur Quality ==
 +
 +
There are only two qualities available.
 +
 +
* low
 +
* default (Assumed to be "medium")
 +
 +
You can set it like this:
 
<source lang="objc">
 
<source lang="objc">
  
        Class UIBackdropView = objc_getClass("_UIBackdropView");
+
[blurView setBlurQuality:@"low"];
        if (UIBackdropView)
+
 
        {
+
</source>
            id settings = nil;
+
 
           
+
== Tinting blur view ==
            Class _UIBackdropViewSettings = objc_getClass("_UIBackdropViewSettings");
+
<source lang="objc">
            if (_UIBackdropViewSettings)
+
 
            {
+
[blurView setRequiresColorStatistics:YES];
                settings = [_UIBackdropViewSettings settingsForStyle:2060]; // 2060 is the system control center background view style
+
[blurView setColorTint:[UIColor cyanColor]];
            }
+
[blurView setColorTintAlpha:0.8];
           
+
[blurView setColorTintMaskAlpha:0.7];
            UIView * backView = (UIView *) [[UIBackdropView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)
+
 
                                                        autosizesToFitSuperview:YES
 
                                                                        settings:settings];
 
            [self addSubview:backView];
 
            [backView release];
 
        }
 
 
</source>
 
</source>
  

Revision as of 16:04, 17 May 2014

_UIBackdropView is a private class in UIKit.framework (iOS 7.0+), a subclass of UIView, which is used for the popular blur effects.

It uses a CABackdropLayer with a gaussianBlur CAFilter.[1]

To create the _UIBackdropView, you need to create its settings first. Here's all settings class available in iOS 7.0

Class name Style number Comments/Used by
_UIBackdropViewSettingsBlur 0 Common blurring
_UIBackdropViewSettingsUltraLight 2010 Some alert views in Settings app & many white UIs
_UIBackdropViewSettingsLight 2020
_UIBackdropViewSettingsDark 2030 iOS 7 Notification Center (?)
_UIBackdropViewSettingsDarkLow 2039
_UIBackdropViewSettingsColored 2040
_UIBackdropViewSettingsUltraDark 2050
_UIBackdropViewSettingsAdaptiveLight 2060 iOS 7 Control Center
_UIBackdropViewSettingsSemiLight 2070
_UIBackdropViewSettingsUltraColored 2080

There are 2 ways to create the settings object

_UIBackdropViewSettings *settings = (_UIBackdropViewSettings *)[[[_UIBackdropViewSettingsSemiLight alloc] init] autorelease];

// or

_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2070];

Creating _UIBackdropView (Blur view) object

_UIBackdropViewSettings *settings = [_UIBackdropViewSettings settingsForStyle:2060];
_UIBackdropView *blurView = [[_UIBackdropView alloc] initWithFrame:CGRectZero
                                              autosizesToFitSuperview:YES settings:settings];
[someView addSubview:backView];
[blurView release];

Blur Quality

There are only two qualities available.

  • low
  • default (Assumed to be "medium")

You can set it like this:

[blurView setBlurQuality:@"low"];

Tinting blur view

[blurView setRequiresColorStatistics:YES];
[blurView setColorTint:[UIColor cyanColor]];
[blurView setColorTintAlpha:0.8];
[blurView setColorTintMaskAlpha:0.7];

References