开发者

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 sp开发者_如何转开发ecific).

How can this be done?


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.


Apple has some great docs for application preferences:

http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/Preferences/Preferences.html

Here's a great library that simplifies some things for you also:

http://www.inappsettingskit.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜