iOS UIBezierPath usesEvenOddFillRule 属性详解

http://stackoverflow.com/questions/24598045/usesevenoddfillrule-example-for-a-donut-with-uikit

为什么在使用UIBezierPath和CAShapeLayer 时设置 UIBezierPath的 usesEvenOddFillRule 属性对 CAShapeLayer最终的效果没有任何影响?

这时因为 UIBezierPath 最终给 CAShapeLayer 赋值的是CGpathRef 而CGpathRe本身并不包含 任何usesEvenOddFillRule属性,这样 path 设置的路径判断规则对 CAShapeLayer 是没有任何效果的

usesEvenOddFillRule example for a donut with UIKit

I'm trying to create a simple donut and add possibly a gradient inside of it depending on how it looks. I've seen a couple examples using Core Graphics. I was wondering how it can be done using UIKit with the usesEvenOddFillRule. So far I've created two basic paths for an inner and outer circle and set the usesEvenOddFillRule to YES. But the donut is still filled all the way. Am I missing something simple here?

CAShapeLayer *layer = (CAShapeLayer *)self.layer;
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
UIBezierPath *outerCircle = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, 4, 4)];
[outerCircle setLineWidth:2.0];
[bezierPath appendPath:outerCircle];

UIBezierPath *innerCircle = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, 20, 20)];
[innerCircle setLineWidth:2.0];
[bezierPath appendPath:innerCircle];
bezierPath.usesEvenOddFillRule = YES;

layer.path = bezierPath.CGPath;
layer.fillColor = [UIColor orangeColor].CGColor;
layer.strokeColor = [UIColor orangeColor].CGColor;

You are creating your UIBezierPath just fine.

Check out fillRule property of CAShapeLayer. You should be setting it to kCAFillRuleEvenOdd.

Notice that CAShapeLayer is taking a CGPathRef and not a UIBezierPath, and CGPathRefdoes not carry fill rule information with it.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值