<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NotTooBad Software &#187; iPhone development</title>
	<atom:link href="http://blog.nottoobadsoftware.com/category/iphone-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nottoobadsoftware.com</link>
	<description>Desktop UX / Software Design</description>
	<lastBuildDate>Sun, 23 Jan 2011 18:33:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Icons for your iPhone settings</title>
		<link>http://blog.nottoobadsoftware.com/2009/11/icons-for-your-iphone-settings/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/11/icons-for-your-iphone-settings/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 18:52:58 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=140</guid>
		<description><![CDATA[bjango.com has an interesting article about how and why many developers are moving their settings into the app itself. They even have some icons you can use, both for the tab bar and the toolbar.]]></description>
			<content:encoded><![CDATA[<p><a href="http://bjango.com/articles/settingsapp/">bjango.com</a> has an interesting article about how and why many developers are moving their settings into the app itself. They even have <a href="http://bjango.com/images/articles/settingsapp/bjango-settings-icons.zip">some icons</a> you can use, both for the tab bar and the toolbar.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/11/icons-for-your-iphone-settings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finally released my first App</title>
		<link>http://blog.nottoobadsoftware.com/2009/09/finally-released-my-first-app/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/09/finally-released-my-first-app/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 12:07:29 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[Repetitions]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=137</guid>
		<description><![CDATA[I finally released my first iPhone app, Repetitions, today. It&#8217;s going to be very interesting to see how it does. After reading about how other apps have done I&#8217;m not very optimistic, especially since the release date of my app was set to 25 August (when it was accepted by Apple) instead of today when [...]]]></description>
			<content:encoded><![CDATA[<p>I finally released my first iPhone app, <a href="itms://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=326304885&amp;mt=8&amp;s=143441">Repetitions</a>, today. It&#8217;s going to be very interesting to see how it does. After reading about how other apps have done I&#8217;m not very optimistic, especially since the release date of my app was set to 25 August (when it was accepted by Apple) instead of today when it was actually released. Which of course means my app now appears on page 6 of the &#8220;Health and Fitness&#8221; category in the AppStore. Where no one will find it. But I will be releasing an update soon anyway, which should put it on the first page at least for a couple of days.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/09/finally-released-my-first-app/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Added mySettings to GitHub</title>
		<link>http://blog.nottoobadsoftware.com/2009/06/added-mysettings-to-github/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/06/added-mysettings-to-github/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 17:14:13 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=126</guid>
		<description><![CDATA[I finally added mySettings to GitHub, using the marvel that is hg-git. It allows me to continue using mercurial, and to push and pull from git repositories. The project on GitHub can be found here. The main place for mySettings will still be on BitBucket, I&#8217;m just uploading the code to GitHub to see if [...]]]></description>
			<content:encoded><![CDATA[<p>I finally added mySettings to GitHub, using the marvel that is <a href="http://bitbucket.org/Scotty/hg-git/overview/">hg-git</a>. It allows me to continue using mercurial, and to push and pull from git repositories. The project on GitHub can be found <a href="http://github.com/kareman/mySettings/tree/master">here</a>. The main place for mySettings will still be on BitBucket, I&#8217;m just uploading the code to GitHub to see if it will attract more users and contributors.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/06/added-mysettings-to-github/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Customising a table view with mySettings</title>
		<link>http://blog.nottoobadsoftware.com/2009/05/customising-a-table-view-with-mysettings/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/05/customising-a-table-view-with-mysettings/#comments</comments>
		<pubDate>Thu, 21 May 2009 18:32:47 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=61</guid>
		<description><![CDATA[I&#8217;ve been working on my iPhone app lately (for performing physical exercises like the ones you get from a physiotherapist, but more about that later) so I haven&#8217;t written anything for a long time. I thought I&#8217;d rectify that by showing how to create highly customised UIs with fairly little coding. I recently added support [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on my iPhone app lately (for performing physical exercises like the ones you get from a physiotherapist, but more about that later) so I haven&#8217;t written anything for a long time. I thought I&#8217;d rectify that by showing how to create highly customised UIs with fairly little coding. I recently added support for delegates to <a href="http://bitbucket.org/karemorstol/mysettings/wiki/Home">mySettings</a> and that opened up a lot of possibilities, even with only one method in the delegate (for now).</p>
<p style="text-align: left;">As an example, here&#8217;s the configuration screen for my app:<br />
<img class="size-full wp-image-66 aligncenter" title="Configuration screen" src="http://blog.nottoobadsoftware.com/wp-content/uploads/2009/05/untitled.jpg" alt="Configuration screen" width="268" height="500" /></p>
<p style="text-align: left;"><span id="more-61"></span>To do this I had to, of course, <a href="http://bitbucket.org/karemorstol/mysettings/wiki/Installation">install mySettings</a>. Then create this plist:</p>
<p><img class="aligncenter size-full wp-image-72" title="Plist configuration file" src="http://blog.nottoobadsoftware.com/wp-content/uploads/2009/05/untitled-2.jpg" alt="Plist configuration file" width="391" height="500" /></p>
<p style="text-align: left;">And configure the table view:</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> <span class="sy0">*</span>plist <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/"><span class="kw5">NSBundle</span></a> mainBundle<span class="br0">&#93;</span> pathForResource<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;ExerciseSettingsView&quot;</span> ofType<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;plist&quot;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">tableviewdelegate <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span>ExerciseSettingsTableViewDelegate alloc<span class="br0">&#93;</span> initWithConfigFile<span class="sy0">:</span>plist andSettings<span class="sy0">:</span>exercise<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">tableviewdelegate.delegate <span class="sy0">=</span> self;</div>
</li>
<li class="li1">
<div class="de1">tableviewdelegate.viewcontroller <span class="sy0">=</span> self;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">tableview.backgroundColor <span class="sy0">=</span> <span class="br0">&#91;</span>UIColor clearColor<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">tableview.rowHeight <span class="sy0">=</span> <span class="nu0">53</span>;</div>
</li>
<li class="li1">
<div class="de1">tableview.separatorStyle <span class="sy0">=</span> UITableViewCellSeparatorStyleSingleLine;</div>
</li>
<li class="li1">
<div class="de1">tableview.separatorColor <span class="sy0">=</span> <span class="br0">&#91;</span>UIColor clearColor<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">tableview.delegate <span class="sy0">=</span> tableviewdelegate;</div>
</li>
<li class="li1">
<div class="de1">tableview.dataSource <span class="sy0">=</span> tableviewdelegate;</div>
</li>
</ol>
</div>
</div>
<p style="text-align: left;">&#8220;exercise&#8221; is the model object containing the values, including the array &#8220;repetitions&#8221; populating the bottom section of the table view. &#8220;ExerciseSettingsTableViewDelegate&#8221;  is a subclass of &#8220;SettingsMetadataSource&#8221; from mySettings. I use it to override</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span>UITableViewCell <span class="sy0">*</span><span class="br0">&#41;</span>tableView<span class="sy0">:</span><span class="br0">&#40;</span>UITableView <span class="sy0">*</span><span class="br0">&#41;</span>tableView cellForRowAtIndexPath<span class="sy0">:</span><span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/"><span class="kw5">NSIndexPath</span></a> <span class="sy0">*</span><span class="br0">&#41;</span>indexPath</div>
</li>
</ol>
</div>
</div>
<p>so I can add on the alternating background images (since I need the row number for that). I also override</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span>CGFloat<span class="br0">&#41;</span>tableView<span class="sy0">:</span><span class="br0">&#40;</span>UITableView <span class="sy0">*</span><span class="br0">&#41;</span>tableView heightForRowAtIndexPath<span class="sy0">:</span><span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/"><span class="kw5">NSIndexPath</span></a> <span class="sy0">*</span><span class="br0">&#41;</span>indexPath</div>
</li>
</ol>
</div>
</div>
<p>to provide the different row heights for the two sections.</p>
<p style="text-align: left;">The bottom section has custom cells, but the top one uses the standard cells from mySettings. To customise the fonts,  colours, background view and accessory view I use the delegate function</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> cellDidInit<span class="sy0">:</span><span class="br0">&#40;</span>SettingsCell <span class="sy0">*</span><span class="br0">&#41;</span>cell</div>
</li>
</ol>
</div>
</div>
<p>which is called right after the cell has been initialised.</p>
<h3>The tricky bit</h3>
<p>Sadly the difficult part is still left; the user needs to be able to add, remove and reorder the cells in the bottom section, and I have not been able to find a way to customise the reorder control. The built-in one looks completely out of place here. Not to mention the red minus sign for removing cells.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/05/customising-a-table-view-with-mysettings/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Another way to create Settings views</title>
		<link>http://blog.nottoobadsoftware.com/2009/05/another-way-to-create-settings-views/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/05/another-way-to-create-settings-views/#comments</comments>
		<pubDate>Mon, 04 May 2009 19:26:56 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=58</guid>
		<description><![CDATA[Craig Hockenberry has also created an API for Settings views. But unlike mySettings his API creates the views from code instead of plists. Like this: - &#40;void&#41;constructTableGroups &#123; NSMutableArray *cells = &#91;NSMutableArray array&#93;; IFTextCellController *textCell = &#91;&#91;&#91;IFTextCellController alloc&#93; initWithLabel:@&#34;Text&#34; andPlaceholder:@&#34;Placeholder&#34; atKey:@&#34;sampleText&#34; inModel:model&#93; autorelease&#93;; &#91;cells addObject:textCell&#93;; IFSwitchCellController *switchCell = &#91;&#91;&#91;IFSwitchCellController alloc&#93; initWithLabel:@&#34;Switch&#34; atKey:@”sampleSwitch” inModel:model&#93; autorelease&#93;; &#91;cells [...]]]></description>
			<content:encoded><![CDATA[<p>Craig Hockenberry has also created an API for Settings views. But unlike <a href="http://bitbucket.org/karemorstol/mysettings/wiki/Home">mySettings</a> his API creates the views from code instead of plists. Like this:</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>constructTableGroups</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span class="kw5">NSMutableArray</span></a> <span class="sy0">*</span>cells <span class="sy0">=</span> <span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/"><span class="kw5">NSMutableArray</span></a> array<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">IFTextCellController <span class="sy0">*</span>textCell <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><span class="br0">&#91;</span>IFTextCellController alloc<span class="br0">&#93;</span> initWithLabel<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Text&quot;</span> andPlaceholder<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Placeholder&quot;</span> atKey<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;sampleText&quot;</span> inModel<span class="sy0">:</span>model<span class="br0">&#93;</span> autorelease<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>cells addObject<span class="sy0">:</span>textCell<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">IFSwitchCellController <span class="sy0">*</span>switchCell <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><span class="br0">&#91;</span>IFSwitchCellController alloc<span class="br0">&#93;</span> initWithLabel<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Switch&quot;</span> atKey<span class="sy0">:</span>@”sampleSwitch” inModel<span class="sy0">:</span>model<span class="br0">&#93;</span> autorelease<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>cells addObject<span class="sy0">:</span>switchCell<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">tableGroups <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span class="kw5">NSArray</span></a> arrayWithObject<span class="sy0">:</span>cells<span class="br0">&#93;</span> retain<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>Check it out at <a href="http://furbo.org/2009/04/30/matt-gallagher-deserves-a-medal/">http://furbo.org/2009/04/30/matt-gallagher-deserves-a-medal/</a> .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/05/another-way-to-create-settings-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Measuring pixels in OS X</title>
		<link>http://blog.nottoobadsoftware.com/2009/04/measuring-pixels-in-os-x/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/04/measuring-pixels-in-os-x/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 18:37:35 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[tips & tricks]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=47</guid>
		<description><![CDATA[I know there are standalone applications for this, but when I need to measure something in one of my applications I find it easiest to just use the screenshot functionality built into OS X. Just press Command-Control-Shift-4 and drag to measure.]]></description>
			<content:encoded><![CDATA[<p>I know there are standalone applications for this, but when I need to measure something in one of my applications I find it easiest to just use the screenshot functionality built into OS X. Just press Command-Control-Shift-4 and drag to measure.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/04/measuring-pixels-in-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A UIPickerView with labels</title>
		<link>http://blog.nottoobadsoftware.com/2009/03/a-uipickerview-with-labels/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/03/a-uipickerview-with-labels/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 18:55:54 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=22</guid>
		<description><![CDATA[I recently needed a picker view with labels (like the one in the timer tab in the Clock app) to select minutes and seconds for a time interval. So I made the following subclass of UIPickerView: #import &#160; /** A picker view with labels under the selection indicator. Similar to the one in the timer [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed a picker view with labels (like the one in the timer tab in the Clock app) to select minutes and seconds for a time interval. So I made the following subclass of UIPickerView:</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">#import</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">A picker view with labels under the selection indicator.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Similar to the one in the timer tab in the Clock app.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">NB: has only been tested with less than four wheels.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">@interface</span> LabeledPickerView <span class="sy0">:</span> UIPickerView <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span class="kw5">NSMutableDictionary</span></a> <span class="sy0">*</span>labels;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** Adds the label for the given component. */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> addLabel<span class="sy0">:</span><span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> <span class="sy0">*</span><span class="br0">&#41;</span>labeltext forComponent<span class="sy0">:</span><span class="br0">&#40;</span>NSUInteger<span class="br0">&#41;</span>component;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">@end</span></div>
</li>
</ol>
</div>
</div>
<p><span id="more-22"></span>&#8230; and the implementation:</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/*******************************************************************************</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* Copyright (c) 2009 Kåre Morstøl (NotTooBad Software).</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* All rights reserved. This program and the accompanying materials</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* are made available under the terms of the Eclipse Public License v1.0</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* which accompanies this distribution, and is available at</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* http://www.eclipse.org/legal/epl-v10.html</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* Contributors:</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* &nbsp; &nbsp;Kåre Morstøl (NotTooBad Software) &#8211; initial API and implementation</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*******************************************************************************/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// http://stackoverflow.com/questions/367471/fixed-labels-in-the-selection-bar-of-a-uipickerview/616517</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#import &quot;LabeledPickerView.h&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">@implementation</span> LabeledPickerView</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** loading programmatically */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>initWithFrame<span class="sy0">:</span><span class="br0">&#40;</span>CGRect<span class="br0">&#41;</span>aRect <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>self <span class="sy0">=</span> <span class="br0">&#91;</span>super initWithFrame<span class="sy0">:</span>aRect<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">labels <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span class="kw5">NSMutableDictionary</span></a> alloc<span class="br0">&#93;</span> initWithCapacity<span class="sy0">:</span>3<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> self;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** loading from nib */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span>initWithCoder<span class="sy0">:</span><span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSCoder_Class/"><span class="kw5">NSCoder</span></a> <span class="sy0">*</span><span class="br0">&#41;</span>coder <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>self <span class="sy0">=</span> <span class="br0">&#91;</span>super initWithCoder<span class="sy0">:</span>coder<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">labels <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span class="kw5">NSMutableDictionary</span></a> alloc<span class="br0">&#93;</span> initWithCapacity<span class="sy0">:</span>3<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> self;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> dealloc</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>labels release<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>super dealloc<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">#pragma mark Labels</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span> addLabel<span class="sy0">:</span><span class="br0">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> <span class="sy0">*</span><span class="br0">&#41;</span>labeltext forComponent<span class="sy0">:</span><span class="br0">&#40;</span>NSUInteger<span class="br0">&#41;</span>component <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>labels setObject<span class="sy0">:</span>labeltext forKey<span class="sy0">:</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span class="kw5">NSNumber</span></a> numberWithInt<span class="sy0">:</span>component<span class="br0">&#93;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">Adds the labels to the view, below the selection indicator glass-thingy.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">The labels are aligned to the right side of the wheel.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">The delegate is responsible for providing enough width for both the value and the label.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>didMoveToWindow <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// exit if view is removed from the window or there are no labels.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>self.window || <span class="br0">&#91;</span>labels count<span class="br0">&#93;</span> <span class="sy0">==</span> 0<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">UIFont <span class="sy0">*</span>labelfont <span class="sy0">=</span> <span class="br0">&#91;</span>UIFont boldSystemFontOfSize<span class="sy0">:</span>20<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// find the width of all the wheels combined</span></div>
</li>
<li class="li1">
<div class="de1">CGFloat widthofwheels <span class="sy0">=</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i<span class="sy0">=</span><span class="nu0">0</span>; i</div>
</li>
<li class="li1">
<div class="de1">widthofwheels <span class="sy0">+=</span> <span class="br0">&#91;</span>self rowSizeForComponent<span class="sy0">:</span>i<span class="br0">&#93;</span>.width;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// find the left side of the first wheel.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// seems like a misnomer, but that will soon be corrected.</span></div>
</li>
<li class="li1">
<div class="de1">CGFloat rightsideofwheel <span class="sy0">=</span> <span class="br0">&#40;</span>self.frame.size.width <span class="sy0">-</span> widthofwheels<span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">2</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// cycle through all wheels</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> component<span class="sy0">=</span><span class="nu0">0</span>; component</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// find the right side of the wheel</span></div>
</li>
<li class="li1">
<div class="de1">rightsideofwheel <span class="sy0">+=</span> <span class="br0">&#91;</span>self rowSizeForComponent<span class="sy0">:</span>component<span class="br0">&#93;</span>.width;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// get the text for the label.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// move on to the next if there is no label for this wheel.</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> <span class="sy0">*</span>text <span class="sy0">=</span> <span class="br0">&#91;</span>labels objectForKey<span class="sy0">:</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span class="kw5">NSNumber</span></a> numberWithInt<span class="sy0">:</span>component<span class="br0">&#93;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>text<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// set up the frame for the label</span></div>
</li>
<li class="li1">
<div class="de1">CGRect frame;</div>
</li>
<li class="li1">
<div class="de1">frame.size <span class="sy0">=</span> <span class="br0">&#91;</span>text sizeWithFont<span class="sy0">:</span>labelfont<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// center it vertically</span></div>
</li>
<li class="li1">
<div class="de1">frame.origin.y <span class="sy0">=</span> <span class="br0">&#40;</span>self.frame.size.height <span class="sy0">/</span> 2<span class="br0">&#41;</span> <span class="sy0">-</span> <span class="br0">&#40;</span>frame.size.height <span class="sy0">/</span> 2<span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">0.5</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// align it to the right side of the wheel, with a margin.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// use a smaller margin for the rightmost wheel.</span></div>
</li>
<li class="li1">
<div class="de1">frame.origin.x <span class="sy0">=</span> rightsideofwheel <span class="sy0">-</span> frame.size.width <span class="sy0">-</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span>component <span class="sy0">==</span> self.numberOfComponents <span class="sy0">-</span> 1 ? 5 <span class="sy0">:</span> 7<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// set up the label</span></div>
</li>
<li class="li1">
<div class="de1">UILabel <span class="sy0">*</span>label <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span><span class="br0">&#91;</span>UILabel alloc<span class="br0">&#93;</span> initWithFrame<span class="sy0">:</span>frame<span class="br0">&#93;</span> autorelease<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">label.text <span class="sy0">=</span> text;</div>
</li>
<li class="li1">
<div class="de1">label.font <span class="sy0">=</span> labelfont;</div>
</li>
<li class="li1">
<div class="de1">label.backgroundColor <span class="sy0">=</span> <span class="br0">&#91;</span>UIColor clearColor<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">label.shadowColor <span class="sy0">=</span> <span class="br0">&#91;</span>UIColor whiteColor<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">label.shadowOffset <span class="sy0">=</span> CGSizeMake<span class="br0">&#40;</span>0,1<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">and now for the tricky bit: adding the label to the view.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">kind of a hack to be honest, might stop working if Apple decides to</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">change the inner workings of the UIPickerView.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>self.showsSelectionIndicator<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// if this is the last wheel, add label as the third view from the top</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>component<span class="sy0">==</span>self.numberOfComponents<span class="sy0">-</span>1<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>self insertSubview<span class="sy0">:</span>label atIndex<span class="sy0">:</span><span class="br0">&#91;</span>self.subviews count<span class="br0">&#93;</span><span class="sy0">-</span>3<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// otherwise add label as the 5th, 10th, 15th etc view from the top</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>self insertSubview<span class="sy0">:</span>label aboveSubview<span class="sy0">:</span><span class="br0">&#91;</span>self.subviews objectAtIndex<span class="sy0">:</span>5<span class="sy0">*</span><span class="br0">&#40;</span>component<span class="sy0">+</span>1<span class="br0">&#41;</span><span class="br0">&#93;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">// there is no selection indicator, so just add it to the top</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>self addSubview<span class="sy0">:</span>label<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">@end</span></div>
</li>
</ol>
</div>
</div>
<p>A big thanks to dizy from <a href="http://stackoverflow.com/questions/367471/fixed-labels-in-the-selection-bar-of-a-uipickerview#616517">stackoverflow.com</a> for showing how to add the labels below the selection indicator.</p>
<p>If anyone knows of a better place to put the label-adding code than didMoveToWindow then please let me know. It seems out of place where it is now.</p>
<p>This class is part of the <a href="http://bitbucket.org/karemorstol/mysettings/wiki/Home">mySettings project</a> and the latest version can always be found here: <a href="http://bitbucket.org/karemorstol/mysettings/raw/tip/Code/Generic classes/LabeledPickerView.h">LabeledPickerView.h</a>, <a href="http://bitbucket.org/karemorstol/mysettings/raw/tip/Code/Generic classes/LabeledPickerView.m">LabeledPickerView.m</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/03/a-uipickerview-with-labels/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>mySettings: A Settings API for the iPhone</title>
		<link>http://blog.nottoobadsoftware.com/2009/03/mysettings-a-settings-api-for-the-iphone/</link>
		<comments>http://blog.nottoobadsoftware.com/2009/03/mysettings-a-settings-api-for-the-iphone/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 19:56:35 +0000</pubDate>
		<dc:creator>Kare</dc:creator>
				<category><![CDATA[iPhone development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mySettings]]></category>

		<guid isPermaLink="false">http://blog.nottoobadsoftware.com/?p=6</guid>
		<description><![CDATA[NB: Unfortunately I am not able to do any more development on this or any other projects. I am hoping that someone else will take over the project and update it. There is also this similar project. A lot of iPhone apps have their own settings views similar to the ones in the Settings App on [...]]]></description>
			<content:encoded><![CDATA[<address>NB: Unfortunately I am not able to do any more development on this or any other projects. I am hoping that someone else will take over the project and update it. There is also <a href="http://bitbucket.org/keegan3d/inappsettings/wiki/Home">this similar project</a>.</address>
<p>A lot of iPhone apps have their own settings views similar to the ones in the Settings App on the iPhone home screen. But to my surprise I couldn&#8217;t find any general API for it. So I made my own and published it <a title="mySettings" href="http://bitbucket.org/karemorstol/mysettings" target="_blank">here</a>. It uses a plist configuration file like the one used by the Settings App, with some added options (and some removed ones, but they will hopefully be implemented in the near future).</p>
<p>In a nutshell it takes a plist like this:</p>
<p><a title="Click for full size" href="http://bitbucket.org/karemorstol/mysettings/wiki/plist_full.jpg"><img title="plist" src="http://bitbucket.org/karemorstol/mysettings/wiki/plist.jpg" alt="plist" /></a></p>
<p>and turns it into this:</p>
<p><img title="iPhone" src="http://bitbucket.org/karemorstol/mysettings/wiki/iPhone.jpg" alt="iPhone" /></p>
<h3>Features</h3>
<ul>
<li>Text fields, on/off switch button, integers and time intervals (with maximum/minimum values and custom format string for the integers).<br />
<em> More options are needed, obviously, like dates and select lists. Feel free to help out if there are other options you would like to see implemented.</em></li>
<li>Titles can be indented.</li>
<li>By default the settings themselves are stored in the standard user defaults object ([NSUserDefaults standardUserDefaults]), but you can use any object that supports key-value coding. This enables you to use your model classes directly in the settings view.</li>
<li>And if you don&#8217;t find blue pyjama stripes exciting, you can of course change the table view background.</li>
</ul>
<p>And that&#8217;s it for the time being. A work in progress, obviously. I would also like to see support for custom table cells and dynamically filling a section with the contents of an array or a dictionary. And localisation. And sliders. And customising fonts and colours. And lots more cool stuff. So if you want to check it out, follow <a title=" Installation instructions" href="http://bitbucket.org/karemorstol/mysettings/wiki/Installation">these instructions</a>. And if you make any changes please let me know so I can merge them back into the repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nottoobadsoftware.com/2009/03/mysettings-a-settings-api-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
	</channel>
</rss>

