Last active
December 21, 2015 06:48
-
-
Save gpake/6266538 to your computer and use it in GitHub Desktop.
In your current code, you save the GState of the current context, configure it to draw a shadow .. and the restore it to what it was before you configured it to draw a shadow. Then, finally, you invoke the superclass's implementation of drawRect:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In your current code, you save the GState of the current context, configure it to draw a shadow .. and the restore it to what it was before you configured it to draw a shadow. Then, finally, you invoke the superclass's implementation of drawRect: . | |
Any drawing that should be affected by the shadow setting needs to happen after | |
CGContextSetShadow(currentContext, CGSizeMake(-15, 20), 5); | |
but before | |
CGContextRestoreGState(currentContext); | |
So if you want the superclass's drawRect: to be 'wrapped' in a shadow, then how about if you rearrange your code like this? | |
- (void)drawRect:(CGRect)rect { | |
CGContextRef currentContext = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(currentContext); | |
CGContextSetShadow(currentContext, CGSizeMake(-15, 20), 5); | |
[super drawRect: rect]; | |
CGContextRestoreGState(currentContext); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Probably the easiest way is to create a shadow, but use a light color instead of a dark one. Shadow details can be found here: How do I draw a shadow under a UIView? and here. | |
Something like this should get the ball rolling: | |
- (void)drawRect:(CGRect)rect | |
{ | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 10, | |
[UIColor whiteColor].CGColor); | |
[super drawRect:rect]; | |
CGContextRestoreGState(context); | |
} | |
Update: I just tried this out. You will have to use this code on the superview of the glowing view for it to work properly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment