我的 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 文件。
更新。我已经修改了代码,因此 IF 语句将始终执行并且它仍然不会加载图像。修改代码如下!
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);