Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ipad 用户触摸屏幕时如何更改uiview颜色_Ipad - Fatal编程技术网

Ipad 用户触摸屏幕时如何更改uiview颜色

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

我正在创建一个ipad应用程序,我有一个按钮,可以创建一个红色填充和蓝色边框的矩形。我想在触摸创建的矩形时更改边框颜色。我应该使用哪种陈述?谢谢

您的矩形和边框颜色是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);
}