3
我用我的UIView子类这段代码画圆用渐变填充:CGContextSetShadow产生任何结果
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow (context, CGSizeMake(4,4), 5);
CGContextBeginPath (context);
CGContextAddEllipseInRect(context, CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 38, 38));
CGContextClosePath (context);
CGContextClip (context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMinX(self.bounds), CGRectGetMaxX(self.bounds)), CGPointMake(CGRectGetMaxX(self.bounds), CGRectGetMinY(self.bounds)), 0);
}
圆和渐变画很好,但我没有看到影子。我不知道为什么它不工作,因为我在不同的视图子类中使用了相同的CGContextSetShadow函数,并且它工作正常。
注意:在上面的代码中,“gradient”是以前定义的ivar。
你的意思是打开或关闭阴影吗?我并不完全了解这一思路。 – indragie
关闭。用它填充,然后将其关闭,并将其关闭。 –