我想在UIImageView上检查背景的颜色集.我试过了:
if(myimage.backgroundColor == [UIColor greenColor]){
...}
else{
...}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,即使我知道颜色是绿色,它总是落入其他部分.
还有,有办法在调试控制台中输出当前颜色.
p [myimage backgroundColor]
Run Code Online (Sandbox Code Playgroud)
和
po [myimage backgroundColor]
Run Code Online (Sandbox Code Playgroud)
不工作.
我正在尝试使用Objective-C编写的代码确定两种颜色是否相同.
我正在使用这段代码来确定这两种颜色是否相同(目前用于调试目的)
NSLog(@"currentColor is %@", currentColor);
NSLog(@"Adjacent Color is %@",[[buttonArray objectAtIndex:1] backgroundColor]);
NSLog(@"%i",[[buttonArray objectAtIndex:1] backgroundColor]==currentColor);
Run Code Online (Sandbox Code Playgroud)
我的控制台正在显示
2009-10-20 00:27:10.814 colorGame[13588:207] currentColor is kCGColorSpaceModelRGB 0 0 1 1
2009-10-20 00:27:10.815 colorGame[13588:207] Adjacent Color is kCGColorSpaceModelRGB 0 0 1 1
2009-10-20 00:27:10.815 colorGame[13588:207] 0
Run Code Online (Sandbox Code Playgroud)
如果被问到我可以发布更多代码(我不知道是否真的有必要).当前颜色最初定义为
UIColor *currentColor;
Run Code Online (Sandbox Code Playgroud)
如果这是任何帮助.
我很确定我只是做比较错误,并且可能有一些可以比较颜色的内置方法,我只是不知道.
objective-c ×2
cocoa-touch ×1
colors ×1
comparison ×1
ios ×1
iphone ×1
uicolor ×1
uiimageview ×1