Created
September 25, 2013 03:35
-
-
Save fjolnir/6694889 to your computer and use it in GitHub Desktop.
A hacked together blur view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface CYBackdropView : UIView | |
@property(nonatomic) UIColor *blurColor; | |
@property(nonatomic) float blurStrength; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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