0

我的 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);
4

1 回答 1

1

代码应该可以工作。要么(1)测试永远不会通过,所以加载图像永远不会被调用,或者(2)dock.png文件没有被正确地添加到项目中,因此它被加载到应用程序包中。

于 2010-08-10T17:42:11.817 回答