And*_*rew 0 iphone core-graphics objective-c
这是我的代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor;
CGRect rectangle = CGRectMake(100, 100, 100, 100);
CGRect inside = CGRectMake(120, 120, 60, 60);
CGContextSetFillColorWithColor(context, redColor);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextFillRect(context, rectangle);
CGContextSaveGState(context);
CGContextSetBlendMode(context, kCGBlendModeSourceOut);
CGContextFillRect(context, inside);
CGContextRestoreGState(context);
Run Code Online (Sandbox Code Playgroud)
我试图让内部形状空心,但是当它背景中的UIView为白色时,它会给我一个红色正方形(作为excetd),中间有一个黑色正方形.
关于如何使形状透明的任何想法?
有几种方法可以用空心内部矩形填充矩形.一种方法是创建一个包含两个矩形的路径,并使用奇偶规则填充它.
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextBeginPath(gc);
CGContextAddRect(gc, CGRectMake(100, 100, 100, 100));
CGContextAddRect(gc, CGRectMake(120, 120, 60, 60));
CGContextSetFillColorWithColor(gc, [UIColor redColor].CGColor);
CGContextEOFillPath(gc);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
342 次 |
| 最近记录: |