This commit is contained in:
Mike Krüger 2011-09-16 06:46:25 +02:00
Родитель 385962350d
Коммит 91a9ee719a
17 изменённых файлов: 660 добавлений и 0 удалений

26
AppPrefs/AppPrefs.sln Normal file
Просмотреть файл

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppPrefs", "AppPrefs\AppPrefs.csproj", "{FBCE3A88-42CC-481E-8190-1DD5154C646D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Debug|iPhone.ActiveCfg = Debug|iPhone
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Debug|iPhone.Build.0 = Debug|iPhone
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Release|iPhone.ActiveCfg = Release|iPhone
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Release|iPhone.Build.0 = Release|iPhone
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{FBCE3A88-42CC-481E-8190-1DD5154C646D}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = AppPrefs\AppPrefs.csproj
EndGlobalSection
EndGlobal

Двоичные данные
AppPrefs/AppPrefs/.DS_Store поставляемый Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace AppPrefs
{
/// <summary>
/// The UIApplicationDelegate for the application. This class is responsible for launching the
/// User Interface of the application, as well as listening (and optionally responding) to
/// application events from iOS.
/// </summary>
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
NSObject observer;
[Export("window")]
public UIWindow Window {
get;
set;
}
public override void FinishedLaunching (UIApplication application)
{
observer = NSNotificationCenter.DefaultCenter.AddObserver ((NSString)"NSUserDefaultsDidChangeNotification", DefaultsChanged);
DefaultsChanged (null);
}
/// <summary>
/// This method is called when the application is about to terminate. Save data, if needed.
/// </summary>
/// <seealso cref="DidEnterBackground"/>
public override void WillTerminate (UIApplication application)
{
if (observer != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver (observer);
observer = null;
}
}
void DefaultsChanged (NSNotification obj)
{
Settings.SetupByPreferences ();
}
}
}

Просмотреть файл

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FBCE3A88-42CC-481E-8190-1DD5154C646D}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>AppPrefs</RootNamespace>
<AssemblyName>AppPrefs</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="AppPrefsViewController.cs" />
<Compile Include="AppPrefsViewController.designer.cs">
<DependentUpon>AppPrefsViewController.cs</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="MainStoryboard.storyboard" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Folder Include="Settings.bundle\" />
<Folder Include="Settings.bundle\en.lproj\" />
</ItemGroup>
<ItemGroup>
<Content Include="Settings.bundle\Root.plist" />
<Content Include="Settings.bundle\en.lproj\Root.strings" />
<Content Include="Images\Icon.png" />
<Content Include="Images\Icon%402x.png" />
<Content Include="Images\Image58.png" />
<Content Include="Images\Image29.png" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,113 @@
using MonoTouch.UIKit;
using System.Drawing;
using System;
using MonoTouch.Foundation;
namespace AppPrefs
{
public partial class AppPrefsViewController : UIViewController
{
NSObject observer;
public AppPrefsViewController (IntPtr handle) : base (handle)
{
}
#region View lifecycle
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
TableView.Source = new MyUITableViewSource ();
observer = NSNotificationCenter.DefaultCenter.AddObserver ((NSString)"NSUserDefaultsDidChangeNotification", UpdateSettings);
}
public override void ViewDidUnload ()
{
base.ViewDidUnload ();
if (observer != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver (observer);
observer = null;
}
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
UpdateSettings (null);
}
#endregion
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
void UpdateSettings (NSNotification obj)
{
// set table view background color
switch (Settings.BackgroundColor) {
case BackgroundColors.Black:
this.TableView.BackgroundColor = UIColor.Black;
break;
case BackgroundColors.White:
this.TableView.BackgroundColor = UIColor.White;
break;
case BackgroundColors.Blue:
this.TableView.BackgroundColor = UIColor.Blue;
break;
case BackgroundColors.Pattern:
this.TableView.BackgroundColor = UIColor.GroupTableViewBackgroundColor;
break;
}
TableView.ReloadData ();
}
#region UITableViewDataSource
class MyUITableViewSource : UITableViewSource
{
public override int NumberOfSections (UITableView tableView)
{
return 1;
}
public override int RowsInSection (UITableView tableview, int section)
{
return 1;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
var kCellIdentifier = new NSString ("MyIdentifier");
var cell = tableView.DequeueReusableCell (kCellIdentifier);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, kCellIdentifier);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
// Get the user settings from the app delegate.
var firstNameStr = Settings.FirstName;
var lastNameStr = Settings.LastName;
cell.TextLabel.Text = firstNameStr + " " + lastNameStr;
switch (Settings.TextColor) {
case TextColors.Blue:
cell.TextLabel.TextColor = UIColor.Blue;
break;
case TextColors.Green:
cell.TextLabel.TextColor = UIColor.Green;
break;
case TextColors.Red:
cell.TextLabel.TextColor = UIColor.Red;
break;
}
return cell;
}
}
#endregion
}
}

17
AppPrefs/AppPrefs/AppPrefsViewController.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,17 @@
// WARNING
//
// This file has been generated automatically by MonoDevelop to store outlets and
// actions made in the Xcode designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using MonoTouch.Foundation;
namespace AppPrefs
{
[Register ("AppPrefsViewController")]
partial class AppPrefsViewController
{
[Outlet]
MonoTouch.UIKit.UITableView TableView { get; set; }
}
}

Двоичные данные
AppPrefs/AppPrefs/Images/Icon.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 932 B

Двоичные данные
AppPrefs/AppPrefs/Images/Icon@2x.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 975 B

Двоичные данные
AppPrefs/AppPrefs/Images/Image29.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 943 B

Двоичные данные
AppPrefs/AppPrefs/Images/Image58.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 963 B

Просмотреть файл

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>Images/Icon.png</string>
<string>Images/Icon@2x.png</string>
<string>Images/Image29.png</string>
<string>Images/Image58.png</string>
</array>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

21
AppPrefs/AppPrefs/Main.cs Normal file
Просмотреть файл

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace AppPrefs
{
public class Application
{
/// <summary>
/// This is the main entry point of the application.
/// </summary>
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}

Просмотреть файл

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.0" toolsVersion="1891" systemVersion="11B26" targetRuntime="iOS.CocoaTouch" nextObjectID="25" propertyAccessControl="none" initialViewController="2">
<dependencies>
<deployment defaultVersion="1280" identifier="iOS"/>
<development defaultVersion="4200" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="884"/>
</dependencies>
<scenes>
<scene sceneID="5">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
<viewController id="2" customClass="AppPrefsViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="9">
<rect key="frame" x="0.0" y="44" width="320" height="416"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" lineBreakMode="clip" id="10">
<rect key="frame" x="0.0" y="22" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" size="system"/>
</tableViewCell>
</prototypes>
</tableView>
<navigationBar contentMode="scaleToFill" id="6">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem title="AppPrefs" id="7">
<barButtonItem key="rightBarButtonItem" title="Info" id="8">
<connections>
<segue destination="11" kind="modal" modalTransitionStyle="flipHorizontal" id="18"/>
</connections>
</barButtonItem>
</navigationItem>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<connections>
<outlet property="TableView" destination="9" id="21"/>
</connections>
</viewController>
</objects>
</scene>
<scene sceneID="14">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="13" userLabel="First Responder" sceneMemberID="firstResponder"/>
<viewController id="11" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="12">
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<navigationBar contentMode="scaleToFill" id="15">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem title="AppPrefs" id="16">
<barButtonItem key="rightBarButtonItem" title="Done" id="17">
<connections>
<segue destination="2" kind="modal" modalTransitionStyle="flipHorizontal" id="19"/>
</connections>
</barButtonItem>
</navigationItem>
</items>
</navigationBar>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="This sample demonstrates how to use application settings from the settings in the system application." lineBreakMode="wordWrap" numberOfLines="5" minimumFontSize="10" id="22">
<rect key="frame" x="20" y="70" width="280" height="86"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" lineBreakMode="wordWrap" numberOfLines="9" minimumFontSize="10" id="23">
<rect key="frame" x="20" y="164" width="280" height="133"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<string key="text">A settings bundle (included in this project) contains the information needed by the settings system application to display the preferences and make the user to modify them. Then the values are saved in the defaults database so that your application can get them at runtime.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Open &quot;Settings&quot; to change the preferences values." lineBreakMode="tailTruncation" numberOfLines="2" minimumFontSize="10" id="24">
<rect key="frame" x="20" y="305" width="280" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
</objects>
<point key="canvasLocation" x="733" y="178"/>
</scene>
</scenes>
<classes>
<class className="AppPrefsViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/AppPrefsViewController.h"/>
<relationships>
<relationship kind="outlet" name="TableView" candidateClass="UITableView"/>
</relationships>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>

Просмотреть файл

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Title</key>
<string>Name</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>Joe</string>
<key>Key</key>
<string>firstNameKey</string>
<key>Title</key>
<string>First</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>Smith</string>
<key>Key</key>
<string>lastNameKey</string>
<key>Title</key>
<string>Last</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>Title</key>
<string>Colors</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<integer>1</integer>
<key>Key</key>
<string>nameColorKey</string>
<key>Title</key>
<string>TextColor</string>
<key>Titles</key>
<array>
<string>Blue</string>
<string>Red</string>
<string>Green</string>
</array>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Values</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
</array>
</dict>
<dict>
<key>DefaultValue</key>
<integer>1</integer>
<key>Key</key>
<string>backgroundColorKey</string>
<key>Title</key>
<string>BackgroundColor</string>
<key>Titles</key>
<array>
<string>Black</string>
<string>White</string>
<string>Blue</string>
<string>Pattern</string>
</array>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Values</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
<integer>4</integer>
</array>
</dict>
</array>
<key>StringsTable</key>
<string>Root</string>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,13 @@
"Name" = "Name";
"Colors" = "Colors";
"First" = "First";
"Last" = "Last";
"TextColor" = "Text Color";
"Blue" = "Blue";
"Red" = "Red";
"Green" = "Green";
"BackgroundColor" = "Background Color";
"Black" = "Black";
"White" = "White";
"Blue" = "Blue";
"Pattern" = "Pattern";

Просмотреть файл

@ -0,0 +1,85 @@
using System;
using MonoTouch.Foundation;
namespace AppPrefs
{
public enum TextColors {
Blue = 1,
Red,
Green
};
public enum BackgroundColors {
Black = 1,
White,
Blue,
Pattern
};
/// <summary>
/// This class manages the system settings.
/// </summary>
public class Settings
{
public static string FirstName { get; private set;}
public static string LastName { get; private set;}
public static TextColors TextColor { get; private set;}
public static BackgroundColors BackgroundColor { get; private set;}
const string firstNameKey = "firstNameKey";
const string lastNameKey = "lastNameKey";
const string nameColorKey = "nameColorKey";
const string backgroundColorKey = "backgroundColorKey";
static void LoadDefaultValues ()
{
var settingsDict = new NSDictionary (NSBundle.MainBundle.PathForResource ("Settings.bundle/Root.plist", null));
var prefSpecifierArray = settingsDict[(NSString)"PreferenceSpecifiers"] as NSArray;
foreach (var prefItem in NSArray.FromArray<NSDictionary> (prefSpecifierArray)) {
var key = prefItem[(NSString)"Key"] as NSString;
if (key == null)
continue;
var val = prefItem[(NSString)"DefaultValue"];
switch (key.ToString ()) {
case firstNameKey:
FirstName = val.ToString ();
break;
case lastNameKey:
LastName = val.ToString ();
break;
case nameColorKey:
TextColor = (TextColors)((NSNumber)val).Int32Value;
break;
case backgroundColorKey:
BackgroundColor = (BackgroundColors)((NSNumber)val).Int32Value;
break;
}
}
var appDefaults = NSDictionary.FromObjectsAndKeys (new object[] {
new NSString (FirstName),
new NSString (LastName),
new NSNumber ((int)TextColor),
new NSNumber ((int)BackgroundColor)
},
new object [] { firstNameKey, lastNameKey, nameColorKey, backgroundColorKey }
);
NSUserDefaults.StandardUserDefaults.RegisterDefaults (appDefaults);
NSUserDefaults.StandardUserDefaults.Synchronize ();
}
public static void SetupByPreferences ()
{
var testValue = NSUserDefaults.StandardUserDefaults.StringForKey (firstNameKey);
if (testValue == null)
LoadDefaultValues ();
FirstName = NSUserDefaults.StandardUserDefaults.StringForKey (firstNameKey);
LastName = NSUserDefaults.StandardUserDefaults.StringForKey (lastNameKey);
TextColor = (TextColors)NSUserDefaults.StandardUserDefaults.IntForKey (nameColorKey);
BackgroundColor = (BackgroundColors)NSUserDefaults.StandardUserDefaults.IntForKey (backgroundColorKey);
}
}
}

14
AppPrefs/README.md Normal file
Просмотреть файл

@ -0,0 +1,14 @@
AppPrefs
===========================
Preview
=======
An example how to diesplay application preferences in the "Settings" system application.
Loosely based on Apple's AppPrefs example:
http://developer.apple.com/library/ios/#samplecode/AppPrefs
Authors
=======
Mike Krüger