Search code examples
objective-cxcodeios6settings.bundle

State of toggle switch in Settings Bundle


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?


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];