Shadows with CoreGraphics?
What is the proper way to implement shadows with CoreGraphics? I've looked around but haven't been able to find a whole lot on it. Is there a simple method for adding a shadow to a开发者_运维问答 view, or will I have to subclass and override the drawRect: method?
You can also use CALayer shadows on any existing view, but the performance penalty is terrible. I don't recommend doing it, especially if you are supporting older devices.
view.layer.shadowOffset = CGSizeMake(2.0, 2.0);
view.layer.shadowColor = [[UIColor blackColor] CGColor];
view.layer.shadowRadius = 3.0;
view.layer.shadowOpacity = 1.0;
See Quartz 2D Programing Guide: Shadows. Basically, you call CGContextSetShadow(CGContextRef context, CGSize shadowSize, CGFloat blurValue)
and then do your drawing.
精彩评论