2

我正在尝试用圆形矩形剪裁矩形,因为矩形的宽度可能只需要绘制部分角。总会有一个背景圆角矩形。

我有以下内容,填充颜色被剪裁,但我也得到了剪裁的灰色背景。我需要做些什么来摆脱这个吗?

// Cell
UIBezierPath *cell = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 133, 55) cornerRadius:10];
[[UIColor greyColor] setFill];
[cell fill];

// Level
UIBezierPath *level = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 129, 55)];
[level fill];

UIBezierPath *clipPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 133, 55) cornerRadius:10];
clipPath.usesEvenOddFillRule = YES;

CGContextSaveGState(UIGraphicsGetCurrentContext()); {
    [clipPath addClip];
    [color setFill];
    [level fill];
} CGContextRestoreGState(UIGraphicsGetCurrentContext());

UIBezierPath *contact = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(135, 19, 5, 17) byRoundingCorners: UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(2.5, 2.5)];
[color setFill];
[contact fill];
4

1 回答 1

0

灰色填充没有被剪辑的原因是它发生在剪辑添加到上下文之前。

[level fill];你在剪辑之前和之后都在做。在剪裁之前取下一个,它应该可以工作。

于 2013-09-18T12:20:22.797 回答