Skip to content

Commit

Permalink
Merge pull request gpambrozio#10 from romaonthego/master
Browse files Browse the repository at this point in the history
Added a nice vignette to the background view
  • Loading branch information
gpambrozio committed Feb 28, 2012
2 parents 43de9fa + 9c7de96 commit 2b81b33
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h
Expand Up @@ -16,6 +16,7 @@
}

@property (nonatomic, readonly) UIView *view;
@property (nonatomic, readwrite) BOOL vignetteBackground;

+ (id)sheetWithTitle:(NSString *)title;

Expand Down
3 changes: 3 additions & 0 deletions BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m
Expand Up @@ -10,6 +10,7 @@
@implementation BlockActionSheet

@synthesize view = _view;
@synthesize vignetteBackground = _vignetteBackground;

static UIImage *background = nil;
static UIFont *titleFont = nil;
Expand Down Expand Up @@ -65,6 +66,7 @@ - (id)initWithTitle:(NSString *)title

_height += size.height + 5;
}
_vignetteBackground = YES;
}

return self;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h
Expand Up @@ -25,5 +25,6 @@

@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, readonly) UIView *view;
@property (nonatomic, readwrite) BOOL vignetteBackground;

@end
5 changes: 4 additions & 1 deletion BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m
Expand Up @@ -11,6 +11,7 @@ @implementation BlockAlertView

@synthesize view = _view;
@synthesize backgroundImage = _backgroundImage;
@synthesize vignetteBackground = _vignetteBackground;

static UIImage *background = nil;
static UIFont *titleFont = nil;
Expand Down Expand Up @@ -95,6 +96,8 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message

_height += size.height + kAlertViewBorder;
}

_vignetteBackground = YES;
}

return self;
Expand Down Expand Up @@ -261,7 +264,7 @@ - (void)show
[_backgroundImage release];
_backgroundImage = nil;
}

[BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
[[BlockBackground sharedInstance] addToMainWindow:_view];

__block CGPoint center = _view.center;
Expand Down
1 change: 1 addition & 0 deletions BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h
Expand Up @@ -20,5 +20,6 @@
- (void)removeView:(UIView *)view;

@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, readwrite) BOOL vignetteBackground;

@end
20 changes: 20 additions & 0 deletions BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m
Expand Up @@ -11,6 +11,7 @@
@implementation BlockBackground

@synthesize backgroundImage = _backgroundImage;
@synthesize vignetteBackground = _vignetteBackground;

static BlockBackground *_sharedInstance = nil;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 2b81b33

Please sign in to comment.