Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created September 25, 2013 03:35
Show Gist options
  • Save fjolnir/6694889 to your computer and use it in GitHub Desktop.
Save fjolnir/6694889 to your computer and use it in GitHub Desktop.
A hacked together blur view
#import <UIKit/UIKit.h>
@interface CYBackdropView : UIView
@property(nonatomic) UIColor *blurColor;
@property(nonatomic) float blurStrength;
@end
#import "CYBackdropView.h"
@interface CYBackdropView () {
UINavigationBar *_navBar;
UIView *_colorView;
}
@end
@implementation CYBackdropView
- (void)_init
{
self.clipsToBounds = YES;
_navBar = [[UINavigationBar alloc] initWithFrame:CGRectInset(self.bounds, 0, -1)];
_navBar.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
_navBar.translucent = YES;
[self addSubview:_navBar];
_colorView = [[UIView alloc] initWithFrame:CGRectInset(self.bounds, 0, -1)];
_colorView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self addSubview:_navBar];
self.blurColor = [UIColor redColor];
self.blurStrength = 0.8;
}
- (id)initWithFrame:(CGRect const)aFrame
{
if((self = [super initWithFrame:aFrame]))
[self _init];
return self;
}
- (id)initWithCoder:(NSCoder * const)aDecoder
{
if((self = [super initWithCoder:aDecoder]))
[self _init];
return self;
}
- (UIColor *)blurColor
{
return _navBar.barTintColor;
}
- (void)setBlurColor:(UIColor *)aColor
{
_colorView.backgroundColor = aColor;
_navBar.barTintColor = aColor;
}
- (float)blurStrength
{
return _navBar.alpha;
}
- (void)setBlurStrength:(float const)aStrength
{
float const strength = 0.9f + aStrength/10.0f;
_navBar.alpha = strength;
_colorView.alpha = (1.0f - strength) / 2.0f;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment