Search code examples
iphoneiossettingsuiwindow

Creating a "settings" option


I want to have a settings toggle on my app's first screen.

On my main view (the first one that shows when the app loads) I have a table. Each cell loads a different view.

I want to have a toggle on my main view that will change a few aspects of how the other views appear (text color and background image to be specific).

How can this be done?


Solution

  • I would recommend using NSUserDefaults. Here is the code that should be activated wherever the user changes their settings.

    [[NSUserDefaults standardUserDefaults] setBOOL:YES forKey@"Whatever"];
    

    And then, in the viewDidLoad part of the new screen, paste this:

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Whatever"] == YES)
    
    {
    
        //Then do your settings here, for example if whatever toggles the color
    
        //then type: view.backgroundColor = [[UIColor redColor];
    
    }
    

    Obviously there are better ways than to use a bool to store info with NSUserDefaults. I would actually read Apple's documentation for this one. It's interesting and makes sense.