UIDevice category to check whether blur is enabled.
This is a hack method to check whether blur is enabled on current device. It is based on testing of rendering blur effect at runtime.
- We create
UIView
with custombackgroundColor
- Add
UIToolbar
withtranslucent = YES
toUIView
- Add
UIView
toUIWindow
beyond the screen (this allows you to performUIView
rendering) - Check rendered colors with tricky algorithm
- Remove
UIView
fromUIWindow
You must check be_blurEffectEnabled
at every applicationDidBecomeActive:
call or by subscribing to UIApplicationDidBecomeActiveNotification
in your controller or custom view to fix views' rendering settings.
'UIView-JTViewToImage', '~> 0.1'
to take screenshot ofUIView
asUIImage
'OBShapedButton', '~> 1.0.2'
to access the pixel color
#import "UIDevice+BlurEnabled.h"
@implementation BEViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIDevice *currentDevice = [UIDevice currentDevice];
NSLog(@"Blur supported by device and OS: %@", [currentDevice be_blurEffectSupported] ? @"YES" : @"NO");
NSLog(@"Blur active ('increase contrast' disabled): %@", [currentDevice be_blurEffectActive] ? @"YES" : @"NO");
NSLog(@"Blur enabled (supported && active): %@", [currentDevice be_blurEffectEnabled] ? @"YES" : @"NO");
}
@end
Alexey Aleshkov
UIDevice-BlurEnabled is available under the BSD 2-Clause license. See the LICENSE
file for more info.