diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h index c5ebd1c..ef160ce 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h @@ -16,6 +16,7 @@ } @property (nonatomic, readonly) UIView *view; +@property (nonatomic, readwrite) BOOL vignetteBackground; + (id)sheetWithTitle:(NSString *)title; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m index d0a91e2..27703c9 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m @@ -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; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 1cf35f0..f984049 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -25,5 +25,6 @@ @property (nonatomic, retain) UIImage *backgroundImage; @property (nonatomic, readonly) UIView *view; +@property (nonatomic, readwrite) BOOL vignetteBackground; @end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index f771333..21134fc 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -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; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h index 79ab0ec..8eabc20 100644 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h @@ -20,5 +20,6 @@ - (void)removeView:(UIView *)view; @property (nonatomic, retain) UIImage *backgroundImage; +@property (nonatomic, readwrite) BOOL vignetteBackground; @end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m index b318b8c..337a494 100644 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m @@ -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