繁体   English   中英

在Objective-C中使用UITouchEvent填充颜色

[英]Fill the colour using UITouchEvent in objective-c

我已将代码用作:-

- (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];


    }

}

在.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; width = 500; height = 500。

一幅图像显示图像,另一幅图像更改图像。

显示的图像是来自AZ的字母。 我使用过UITouch event.So当显示字母时,我调用touch事件。以显示下一个字母。

我使用了一个按钮来显示下一个。因此,当我单击下一个按钮时,字母将发生变化。

我在code.in中使用了名为selectedColor的颜色,因此我可以在字母中填充颜色。

但是我需要满足以下条件:如果颜色未完全填充,则显示警报。该怎么办?

通过使用下面的代码,您可以获取imageview的背景色。

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

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

if([imageviewOneColor isEqual: imageviewTwoColor]){

    NSLog(@"same colour");

}else{

    NSLog(@"Different colour");

    your alert - As folows
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM