我在drawRect方法我在UIBezierPath添加到显示在一个广场上阴影的UIView和委托方法。更改阴影的颜色上UIBezierPath
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();
//// Shadow Declarations
UIColor* shadow = [UIColor blackColor];
CGSize shadowOffset = CGSizeMake(0, -0);
CGFloat shadowBlurRadius = 15;
//// Rectangle Drawing
rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(8, 8, 44, 44)];
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor);
[[UIColor whiteColor] setFill];
[rectanglePath fill];
CGContextRestoreGState(context);
然后我想改变基于特定标准的阴影的颜色,所以我MAVE一个名为makeRed方法。
- (void)makeRed {
NSLog(@"makeRed");
CGContextRef context = UIGraphicsGetCurrentContext();
// Shadow Declarations
UIColor* shadow = [UIColor redColor];
CGSize shadowOffset = CGSizeMake(0, -0);
CGFloat shadowBlurRadius = 15;
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor);
[[UIColor whiteColor] setFill];
[rectanglePath fill];
CGContextRestoreGState(context);
}
但是当我调用该方法我得到的消息:
:CGContextSaveGState:无效的情况下为0x0
任何想法如何,我可以设置正确的上下文或更改阴影颜色不同办法?
注意阴影的初始绘图作品完美,因为有其他属性的委托,即使用创建的阴影不会工作的.layer方法一些花哨的动画。
干杯
这完美的作品 - 由于负载(如果我能记得的我的旧登录我本来还有代表以给予好评本 - 遗憾的是我已经重新加入让着它给予好评) – Dominic