2012-11-12 42 views
0

我有UIImageView什麼在View中有一個背景圖像的角色。我想在此UIImageView中加載兩個不同的圖像,具體取決於Settings Bundle中切換開關選擇的狀態。設置包中的切換開關的狀態

什麼是最好的辦法呢?

回答

1

嘗試這樣:

NSUserDefaults* settings = [NSUserDefaults standardUserDefaults]; 
NSString* imgName = [settings boolForKey:@"toggle_switch"] ? @"switch_on.png" : @"switch_off.png"; 
UIImage* img = [UIImage imageNamed:imgName]; 
[imageView setImage:img]; 
+0

謝謝指教! – Alex