0
NSString *devicetype;
if((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)){
devicetype = @"ipad";
}else{
devicetype = @"iphone";
}
我有兩個圖像追加字符串通過變量傳遞客觀C到文件名
BACKGROUND_IPAD.PNG
和
BACKGROUND_IPHONE.PNG
現在我想要使用此字符串,如
BackGround = [CCSprite spriteWithFile:[NSString StringWithFormat:@"background_%@.png",DEVICETYPE]];
這可能嗎? 如果沒有,那麼有沒有更好的方法?
即使是這樣,使用imagenamed更好 –
@Omar Abdelhafith [link] http://stackoverflow.com/questions/6623295/imagenamed-is-evil-how-to-use-the-function - 評論黑暗塵埃說,以避免使用** imagenamed **。還有其他方式會使用更多的處理,所以我認爲使用手動命名更好。 – maniclorn
是在較舊的ios版本,爲新版本閱讀http://stackoverflow.com/questions/924740/dispelling-the-uiimage-imagenamed-fud –