Permalink
Browse files

Added vignette background

  • Loading branch information...
1 parent 43de9fa commit 9c7de96f3ed3f64763402319f1135b7c9f846e93 @romaonthego romaonthego committed Feb 28, 2012
@@ -16,6 +16,7 @@
}
@property (nonatomic, readonly) UIView *view;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
+ (id)sheetWithTitle:(NSString *)title;
@@ -10,6 +10,7 @@
@implementation BlockActionSheet
@synthesize view = _view;
+@synthesize vignetteBackground = _vignetteBackground;
static UIImage *background = nil;
static UIFont *titleFont = nil;
@@ -65,6 +66,7 @@ - (id)initWithTitle:(NSString *)title
_height += size.height + 5;
}
+ _vignetteBackground = YES;
}
return self;
@@ -172,6 +174,7 @@ - (void)showInView:(UIView *)view
[_view insertSubview:modalBackground atIndex:0];
[modalBackground release];
+ [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
[[BlockBackground sharedInstance] addToMainWindow:_view];
CGRect frame = _view.frame;
frame.origin.y = [BlockBackground sharedInstance].bounds.size.height;
@@ -25,5 +25,6 @@
@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, readonly) UIView *view;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
@end
@@ -11,6 +11,7 @@ @implementation BlockAlertView
@synthesize view = _view;
@synthesize backgroundImage = _backgroundImage;
+@synthesize vignetteBackground = _vignetteBackground;
static UIImage *background = nil;
static UIFont *titleFont = nil;
@@ -95,6 +96,8 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message
_height += size.height + kAlertViewBorder;
}
+
+ _vignetteBackground = YES;
}
return self;
@@ -261,7 +264,7 @@ - (void)show
[_backgroundImage release];
_backgroundImage = nil;
}
-
+ [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
[[BlockBackground sharedInstance] addToMainWindow:_view];
__block CGPoint center = _view.center;
@@ -20,5 +20,6 @@
- (void)removeView:(UIView *)view;
@property (nonatomic, retain) UIImage *backgroundImage;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
@end
@@ -11,6 +11,7 @@
@implementation BlockBackground
@synthesize backgroundImage = _backgroundImage;
+@synthesize vignetteBackground = _vignetteBackground;
static BlockBackground *_sharedInstance = nil;
@@ -73,6 +74,7 @@ - (id)init
self.hidden = YES;
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f];
+ self.vignetteBackground = YES;
}
return self;
}
@@ -140,4 +142,22 @@ - (void)removeView:(UIView *)view
}
}
+- (void)drawRect:(CGRect)rect
+{
+ if (_backgroundImage || !_vignetteBackground) return;
+ CGContextRef context = UIGraphicsGetCurrentContext();
+
+ size_t locationsCount = 2;
+ CGFloat locations[2] = {0.0f, 1.0f};
+ CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
+ CGColorSpaceRelease(colorSpace);
+
+ CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
+ float radius = MIN(self.bounds.size.width , self.bounds.size.height) ;
+ CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation);
+ CGGradientRelease(gradient);
+}
+
@end

0 comments on commit 9c7de96

Please sign in to comment.