Skip to content

Commit

Permalink
Add useThinGradients and fix running on iOS 6 when compiled with iO…
Browse files Browse the repository at this point in the history
…S 7.
  • Loading branch information
soffes committed Jul 29, 2013
1 parent fc89649 commit 62368c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions SAMGradientView/SAMGradientView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ typedef enum : NSUInteger {
/// @name Drawing the Borders
///--------------------------

/**
Use thin borders.
1px borders will be drawn instead of 1pt borders. The default is `NO`.
*/
@property (nonatomic) BOOL useThinBorders;

/**
The top border color. The default is `nil`.
Expand Down
17 changes: 12 additions & 5 deletions SAMGradientView/SAMGradientView.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation SAMGradientView
@synthesize gradientColors = _gradientColors;
@synthesize gradientLocations = _gradientLocations;
@synthesize gradientDirection = _gradientDirection;
@synthesize useThinBorders = _useThinBorders;
@synthesize topBorderColor = _topBorderColor;
@synthesize topInsetColor = _topInsetColor;
@synthesize rightBorderColor = _rightBorderColor;
Expand Down Expand Up @@ -84,6 +85,12 @@ - (void)setDimmedGradientColors:(NSArray *)colors {
#endif


- (void)setUseThinBorders:(BOOL)useThinBorders {
_useThinBorders = useThinBorders;
[self setNeedsDisplay];
}


- (void)setTopBorderColor:(UIColor *)topBorderColor {
_topBorderColor = topBorderColor;
[self setNeedsDisplay];
Expand Down Expand Up @@ -161,7 +168,7 @@ - (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();

CGSize size = self.bounds.size;
CGFloat const borderWidth = 1.0f;
CGFloat borderWidth = self.useThinBorders ? 1.0f / [[UIScreen mainScreen] scale] : 1.0f;

// Gradient
if (self.gradient) {
Expand All @@ -184,14 +191,14 @@ - (void)drawRect:(CGRect)rect {
}
}

CGFloat sideY = self.topBorderColor ? 1.0f : 0.0f;
CGFloat sideY = self.topBorderColor ? borderWidth : 0.0f;
CGFloat sideHeight = size.height;
if (self.topBorderColor) {
sideHeight -= 1.0f;
sideHeight -= borderWidth;
}

if (self.bottomBorderColor) {
sideHeight -= 1.0f;
sideHeight -= borderWidth;
}

// Right
Expand Down Expand Up @@ -252,7 +259,7 @@ - (void)initialize {

- (void)refreshGradient {
#ifdef __IPHONE_7_0
if (self.tintAdjustmentMode == UIViewTintAdjustmentModeDimmed) {
if ([self respondsToSelector:@selector(tintAdjustmentMode)] && self.tintAdjustmentMode == UIViewTintAdjustmentModeDimmed) {
NSArray *locations = self.dimmedGradientColors.count == self.gradientLocations.count ? self.gradientLocations : nil;
self.gradient = SAMGradientCreateWithColorsAndLocations(self.dimmedGradientColors, locations);
return;
Expand Down

0 comments on commit 62368c2

Please sign in to comment.