私はiPadアプリを作成しています.赤い塗りつぶしと青い境界線を持つ長方形を作成できるボタンがあります. 作成した四角形をタッチした時の枠線の色を変えたいです。どのステートメントを使用する必要がありますか? ありがとう
1 に答える
0
yourRect と borderColor は iVar です。長方形がタッチされるたびに色を変更するロジックのためにメソッド changeBorderColor を記述する必要があります。
- (void) init
{
yourRect = CGRectMake(100,100, 200,200);
borderColor = [UIColor blueColor];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleTap:];
[singleTap release];
}
-(void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint tapLocation = [gestureRecognizer locationInView:shareView];
if(CGRectContainsPoint(yourRect, tapLocation))
{
borderColor = [self changeBorderColor]; //Change color
}
}
- (void)drawRect:(CGRect)rect;
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillRect(context, yourRect);
CGContextSetStrokeColorWithColor(context, borderColor.CGColor);
CGContextStrokeRect(context, yourRect);
}
于 2012-07-06T19:05:37.390 に答える