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文件。
UPDATE。我已經修改了代碼,因此如果陳述將始終執行,並且它仍然不會載入圖像。修改後的代碼!
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);
該文件在那裏。我點擊並拖動到項目 - >資源文件夾,並將其複製到目標 – 2010-08-10 18:11:42
該測試確實通過,因爲我調試了它,並且我輸入了if語句 – 2010-08-10 18:12:07
我會記錄圖像本身並確保您有UIImage對象,並且不是零。如果它是零,則'dock.png'文件沒有正確添加到目標。 – TechZen 2010-08-11 18:50:18