使用objective-c中的UITouchEvent填充颜色

问题描述 投票:0回答:1

我使用的代码如下: -

- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event

{

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint location = [touch locationInView:_alphabetBackgroundImageView];

   if((location.x > 50 && location.x < _alphabetBackgroundImageView.frame.size.width-50) && (location.y > 50 && location.y < _alphabetBackgroundImageView.frame.size.height-50))

   {

        UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];

        lineImageView.center = location;

        lineImageView.backgroundColor = selectedColor;

        [_alphabetBackgroundImageView addSubview:lineImageView];

   }

}



- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event

{
    UITouch *touch = [[event allTouches] anyObject];

    CGPoint location = [touch locationInView:_alphabetBackgroundImageView];

    if((location.x > 50 && location.x < _alphabetBackgroundImageView.frame.size.width-50) && (location.y > 50 && location.y < _alphabetBackgroundImageView.frame.size.height-50))
    {

        UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];

        lineImageView.center = location;

        lineImageView.backgroundColor = selectedColor;

        [_alphabetBackgroundImageView addSubview:lineImageView];

    }

}



- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [[event allTouches] anyObject];

    CGPoint location = [touch locationInView:_alphabetBackgroundImageView];




   if((location.x > 50 && location.x < _alphabetBackgroundImageView.frame.size.width-50) && (location.y > 50 && location.y < _alphabetBackgroundImageView .frame.size.height-50))
    {

        UIImageView *lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];

        lineImageView.center = location;

        lineImageView.backgroundColor = selectedColor;

        [_alphabetBackgroundImageView addSubview:lineImageView];


    }

}

IN .h文件:

@property (strong, nonatomic) IBOutlet UIImageView *alphabetBackgroundImageView;

在.m文件中: -

alphabetsStoreArray = [[NSMutableArray alloc]initWithObjects:@"write a.png",@"write b.png",@"write c.png",@"write d.png",@"write e.png",@"write f.png",@"write g.png",@"write h.png",@"write i.png",@"write j.png",@"write k.png",@"write l.png",@"write m.png",@"write n.png",@"write o.png",@"write p.png",@"write q.png",@"write r.png",@"write s.png",@"write t.png",@"write u.png",@"write v.png",@"write w.png",@"write x.png",@"write y.png",@"write z.png", nil];

 selectedColor = [UIColor colorWithRed:181/255.0 green:218/255.0 blue:234/255.0 alpha:1.0];

我使用了两个UIImageView并将这两个图像放在同一位置。位置:-x = 492.5; y = 323;宽度= 500;高度= 500。

一个图像显示图像,另一个图像改变图像。

图像显示是来自A-Z的字母。我使用了UITouch event.So当显示的字母我调用触摸事件时。显示下一个字母。

我用了一个按钮来显示下一个。所以当我点击下一个按钮时,这封信就会改变。

我在代码中使用了颜色作为名为selectedColor。所以我可以填写字母中的颜色。

但我需要的条件是,如果颜色完全没有填充然后显示警报。怎么办?

ios objective-c
1个回答
0
投票

通过使用Below代码,您可以获得imageview的背景颜色。

UIColor *imageviewOneColor = yourImageviewOne.backgroundColor;
UIColor *imageviewTwoColor = yourImageviewTwo.backgroundColor;

因此,您可以尝试以下代码来检查两个图像背景颜色是否相同。

if([imageviewOneColor isEqual: imageviewTwoColor]){

    NSLog(@"same colour");

}else{

    NSLog(@"Different colour");

    your alert - As folows
}
© www.soinside.com 2019 - 2024. All rights reserved.