Question

I have UIImageView what have a role of a background image in View. I want to load two different images in this UIImageView, depending on what state is selected in toggle switch in Settings Bundle.

What the best way to do it?

Was it helpful?

Solution

Try something like this:

NSUserDefaults* settings = [NSUserDefaults standardUserDefaults];
NSString* imgName = [settings boolForKey:@"toggle_switch"] ? @"switch_on.png" : @"switch_off.png";
UIImage* img = [UIImage imageNamed:imgName];
[imageView setImage:img];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top