Ipad 用户触摸屏幕时如何更改uiview颜色
我正在创建一个ipad应用程序,我有一个按钮,可以创建一个红色填充和蓝色边框的矩形。我想在触摸创建的矩形时更改边框颜色。我应该使用哪种陈述?谢谢您的矩形和边框颜色是IVAR。您必须编写方法changeBorderColor,以便在每次触摸矩形时更改颜色的逻辑Ipad 用户触摸屏幕时如何更改uiview颜色,ipad,Ipad,我正在创建一个ipad应用程序,我有一个按钮,可以创建一个红色填充和蓝色边框的矩形。我想在触摸创建的矩形时更改边框颜色。我应该使用哪种陈述?谢谢您的矩形和边框颜色是IVAR。您必须编写方法changeBorderColor,以便在每次触摸矩形时更改颜色的逻辑 - (void) init { yourRect = CGRectMake(100,100, 200,200); borderColor = [UIColor blueColor]; UITapGestureRecognize
- (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);
}