我使用的代码为: -
- (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的颜色。所以我可以填写字母中的颜色。
但我需要的条件是,如果颜色完全没有填充,那么显示警告。怎么做?
答案 0 :(得分:0)
通过使用下面的代码,您可以获得imageview的背景颜色。
UIColor *imageviewOneColor = yourImageviewOne.backgroundColor;
UIColor *imageviewTwoColor = yourImageviewTwo.backgroundColor;
因此,您可以尝试以下代码来检查两个图像背景颜色是否相同。
if([imageviewOneColor isEqual: imageviewTwoColor]){
NSLog(@"same colour");
}else{
NSLog(@"Different colour");
your alert - As folows
}