我在 - LayoutView 中画了 3 个正方形
- (void)drawRect:(CGRect)rect
self.room1 = [UIBezierPath bezierPathWithRect:CGRectMake(81, 10, 60, 60)];
[self.normalColor setFill];
[self.room1 fill];
[[UIColor blackColor]setStroke];
self.room1.lineWidth = 1;
[self.room1 stroke];
然后我找到正确的 UIBezierPath
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touch here");
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
if ([self.room1 containsPoint:touchPoint])
{
// do stuff
NSLog(@"room1 %@" , self.room1);
[[UIColor redColor] setFill];
[self.room1 fill];
[self setNeedsDisplay];
}
}
这是工作我触摸房间 1 和日志打印“room1”
但是如何更改 room1 的颜色?
目前我收到一个错误
:CGContextSetFillColorWithColor:无效的上下文0x0。这是一个严重的错误。...
谢谢你的帮助。