我的iPhone项目中有一张图片。这是一个PNG,我可以在Interface Builder中设置背景,但我想以编程方式执行此操作。
NSLog(@"Before %@", myEasterEgg);
uiImageBackground.backgroundColor = [UIColor purpleColor];
myEasterEgg = [myEasterEgg stringByAppendingString:@"5"];
NSLog(@"After %@", myEasterEgg);
if (CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0) {
myEasterEgg = @"";
uiImageBackground.backgroundColor = [UIColor clearColor];
[uiImageBackground setImage:[UIImage imageNamed:@"dock.png"]];
uiImageBackground.image = image;
}
[myEasterEgg retain];
NSLog(@"After %@", myEasterEgg);
以上是我的按钮中的代码。它不显示dock.png文件。
更新。我修改了代码,因为如果声明总是会执行,而且它仍然没有加载图像。修改后的代码!
NSLog(@"Before %@", myEasterEgg);
uiImageBackground.backgroundColor = [UIColor purpleColor];
myEasterEgg = [myEasterEgg stringByAppendingString:@"5"];
NSLog(@"After %@", myEasterEgg);
myEasterEgg = @"";
uiImageBackground.backgroundColor = [UIColor clearColor];
[uiImageBackground setImage:[UIImage imageNamed:@"dock.png"]];
uiImageBackground.image = image;
[myEasterEgg retain];
NSLog(@"After %@", myEasterEgg);
答案 0 :(得分:1)
代码应该有效。 (1)测试从未通过,因此永远不会调用加载图像或(2)dock.png
文件未正确添加到项目中,以便将其加载到应用程序包中。