Permalink
Browse files

Fix shadow drawing for AJPanelPositionBottom

  • Loading branch information...
1 parent a861710 commit de50a6be7948cf45d7f0537c71a14bde88faeeff @ajerez committed Sep 4, 2012
@@ -29,6 +29,7 @@ @interface AJProgressLayer : CALayer
@property (nonatomic, strong) UIColor *endGradientColor;
@property (nonatomic, strong) UIColor *stripesColor;
@property (nonatomic, assign) BOOL enableShadow;
+@property (nonatomic, assign) int thePosition;
@property (nonatomic, assign) CGFloat progress;
@property (nonatomic, assign) CGFloat moveFactor;
@property (nonatomic, strong) UIColor *progressColor;
@@ -42,6 +43,7 @@ - (id)initWithLayer:(AJProgressLayer *)layer{
if (self){
self.progress = layer.progress;
self.enableShadow = layer.enableShadow;
+ self.thePosition = layer.thePosition;
self.stripesColor = layer.stripesColor;
self.endGradientColor = layer.endGradientColor;
self.startGradientColor = layer.startGradientColor;
@@ -59,7 +61,6 @@ + (BOOL)needsDisplayForKey:(NSString *)key{
}
- (void)drawInContext:(CGContextRef)ctx{
-
CGRect rect = self.bounds;
CGContextClipToRect(ctx, rect);
@@ -98,6 +99,15 @@ - (void)drawInContext:(CGContextRef)ctx{
CGContextDrawPath(ctx, kCGPathStroke);
CGContextRestoreGState(ctx);
+ // Draw Shadow
+ if (self.enableShadow){
+ CGFloat fixedOffset = (self.thePosition == 0 ? 1.0f : -1.0);
+ self.shadowColor = [UIColor blackColor].CGColor;
+ self.shadowOpacity = 0.5f;
+ self.shadowOffset = CGSizeMake(0.0, fixedOffset);
+ self.shadowRadius = 2.0f;
+ }
+
// Progress
if (self.progress != 0.0f){
CGContextSaveGState(ctx);
@@ -248,14 +258,17 @@ - (BOOL)enableShadow{
- (void)setEnableShadow:(BOOL)enableShadow
{
[self currentLayer].enableShadow = enableShadow;
- // Draw Shadow
- if (self.enableShadow){
- CGFloat fixedOffset = (self.position == AJPanelPositionTop ? 1.0f : -1.0);
- self.layer.shadowColor = [UIColor blackColor].CGColor;
- self.layer.shadowOpacity = 0.5f;
- self.layer.shadowOffset = CGSizeMake(0.0, fixedOffset);
- self.layer.shadowRadius = 2.0f;
- }
+ [[self currentLayer] setNeedsDisplay];
+}
+
+#pragma mark position
+- (AJPanelPosition)position{
+ return [self currentLayer].thePosition;
+}
+
+- (void)setPosition:(AJPanelPosition)position
+{
+ [self currentLayer].thePosition = position;
[[self currentLayer] setNeedsDisplay];
}
@@ -268,7 +281,7 @@ + (AJProgressPanel *)showInView:(UIView *)view{
+ (AJProgressPanel *)showInView:(UIView *)view position:(AJPanelPosition)position {
CGFloat fixedY = (position == AJPanelPositionTop ? 0.0f : view.bounds.size.height);
AJProgressPanel *progressView = [[self alloc] initWithFrame:CGRectMake(0.0f, fixedY, view.bounds.size.width, 1.0f)];
- progressView.position = (position == AJPanelPositionTop ? AJPanelPositionTop : AJPanelPositionBottom);
+ progressView.position = position;
[view addSubview:progressView];
@@ -36,7 +36,7 @@ - (void)showPanels{
//Custom
self.panel2 = [AJProgressPanel showInView:self.secondView position:AJPanelPositionBottom];
- self.panel2.enableShadow = NO;
+ //self.panel2.enableShadow = NO;
self.panel2.startGradientColor = [UIColor colorWithWhite:0.35f alpha:1.0f];
self.panel2.endGradientColor = [UIColor colorWithWhite:0.25f alpha:1.0f];
self.panel2.stripesColor = [UIColor colorWithRed:40.0f/255 green:140.0f/255 blue:193.0f/255 alpha:1.0f];

0 comments on commit de50a6b

Please sign in to comment.