Skip to content

Commit

Permalink
Add patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
peyton committed Feb 26, 2012
1 parent b9e1bf1 commit 8aa3939
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
14 changes: 13 additions & 1 deletion MOOMaskedIconView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ typedef enum {

UIColor *_color;
UIColor *_highlightedColor;
UIColor *_pattern;
CGBlendMode _patternBlendMode;
UIImage *_overlay;
CGBlendMode _overlayBlendMode;

Expand Down Expand Up @@ -133,6 +135,16 @@ typedef enum {
*/
@property (nonatomic, strong) UIColor *highlightedColor;

/*
* A pattern composited over the icon. Created with UIColor's colorWithPatternImage:.
*/
@property (nonatomic, strong) UIColor *pattern;

/*
* The blend mode under which the pattern is drawn. Defaults to kCGBlendModeNormal. For a list of options see "CGBlendMode".
*/
@property (nonatomic, assign) CGBlendMode patternBlendMode;

/*
* An image composited over the icon after drawing's done.
*
Expand All @@ -141,7 +153,7 @@ typedef enum {
@property (nonatomic, strong) UIImage *overlay;

/*
* The blend mode under which the overlay is drawn. Defaults to kCGBlendModeNormal. For a list of options see "CGBlendMode"
* The blend mode under which the overlay is drawn. Defaults to kCGBlendModeNormal. For a list of options see "CGBlendMode".
*
* @see overlay
*/
Expand Down
22 changes: 19 additions & 3 deletions MOOMaskedIconView.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ @implementation MOOMaskedIconView

@synthesize color = _color;
@synthesize highlightedColor = _highlightedColor;
@synthesize pattern = _pattern;
@synthesize patternBlendMode = _patternBlendMode;
@synthesize overlay = _overlay;
@synthesize overlayBlendMode = _overlayBlendMode;

Expand Down Expand Up @@ -79,6 +81,7 @@ - (id)initWithFrame:(CGRect)frame
// Set view defaults
self.backgroundColor = [UIColor clearColor];
self.color = [UIColor blackColor];
self.patternBlendMode = kCGBlendModeNormal;
self.overlayBlendMode = kCGBlendModeNormal;

// Set up observing
Expand Down Expand Up @@ -174,13 +177,17 @@ - (void)dealloc;

self.color = nil;
self.highlightedColor = nil;
self.shadowColor = nil;
self.gradientColors = nil;
self.gradientLocations = nil;
self.pattern = nil;
self.overlay = nil;
self.drawingBlock = NULL;
self.mask = NULL;
self.gradient = NULL;
self.gradientColors = nil;
self.gradientLocations = nil;
self.shadowColor = nil;
self.innerShadowColor = nil;
self.outerGlowColor = nil;
self.innerGlowColor = nil;

AH_SUPER_DEALLOC;
}
Expand Down Expand Up @@ -287,6 +294,15 @@ - (void)drawRect:(CGRect)rect
}
CGContextRestoreGState(context); // Restore state after filling

if (self.pattern)
{
CGContextSaveGState(context);
CGContextSetBlendMode(context, self.patternBlendMode);
[self.pattern set];
CGContextFillRect(context, imageRect);
CGContextRestoreGState(context);
}

CGContextRestoreGState(context); // Pop state clipping to icon

// Draw inner glow
Expand Down

0 comments on commit 8aa3939

Please sign in to comment.