我想改变两个圆圈交叉的颜色。
我现在使用这种方法:
- (void)drawRect:(CGRect)rect{
// draw circle 1
CGRect circle1=CGRectMake(100, 200, 80, 80);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddArc(ctx, CGRectGetMinX(circle1), CGRectGetMinY(circle1), CGRectGetWidth(circle1)/2, 0, 2*M_PI, 1);
CGContextSetFillColorWithColor(ctx, [UIColor blackColor].CGColor);
CGContextDrawPath(ctx, kCGPathFill);
// draw circle 2
CGRect circle2=CGRectMake(170, 200, 80, 80);
CGContextAddArc(ctx, CGRectGetMinX(circle2), CGRectGetMinY(circle2), CGRectGetWidth(circle2)/2, 0, 2*M_PI, 1);
CGContextSetFillColorWithColor(ctx, [UIColor blackColor].CGColor);
CGContextDrawPath(ctx, kCGPathFill);
// intersection Rect
CGRect intersectionRect=CGRectIntersection(circle1, circle2);
}
获取交叉点位置,但接下来该做什么?
如图所示,我想将两个黑色圆圈的交点更改为白色。
答案 0 :(得分:0)
如果他们是recatangles:
let v1 = UIView()
v1.frame = CGRect(x: 50, y: 50, width: 100, height: 100)
v1.backgroundColor = UIColor.blue
self.view.addSubview(v1)
let v2 = UIView()
v2.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
v2.backgroundColor = UIColor.yellow
self.view.addSubview(v2)
let v3 = UIView()
v3.frame = v1.frame.intersection(v2.frame)
v3.backgroundColor = UIColor.green
self.view.addSubview(v3)