<?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>mostly a codeBlog &#187; iPhone</title>
	<atom:link href="http://www.rickigregersen.com/tag/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rickigregersen.com</link>
	<description>whatever I am currently programming... and I truly digress</description>
	<lastBuildDate>Mon, 21 Jun 2010 15:40:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Customizing the UINavigationController</title>
		<link>http://www.rickigregersen.com/2010/06/16/customizing-the-uinavigationcontroller/</link>
		<comments>http://www.rickigregersen.com/2010/06/16/customizing-the-uinavigationcontroller/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:45:52 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Customize]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[UInavigationBar]]></category>
		<category><![CDATA[UInavigationController]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=229</guid>
		<description><![CDATA[I had to add some new tags to my blog as the content will mostly be Cocoa Touch, Objective C, iPhone stuff from now on. I think the UINavigationController is by far the most widely used Controller-controller. Out of the box the API&#8217;s for customizing the looks of the UINavigatioController are limited to setting a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I had to add some new tags to my blog as the content will <em>mostly </em>be Cocoa Touch, Objective C, iPhone stuff from now on.</strong></p>
<p>I think the UINavigationController is by far the most widely used Controller-controller.</p>
<p>Out of the box the API&#8217;s for customizing the looks of the UINavigatioController are limited to setting a tint for the background color.</p>
<p>I am doing an iPhone app and I would like to have the freedom to set the title label, the color, background image and the buttons to whatever I like. I, however, do not want to get rejected by the App Store approval process or implement my own controller, so in this post I&#8217;ll deliver some <em>Proof-of-Concept</em> code for how to do this.</p>
<h3><strong>The product:</strong></h3>
<div id="attachment_232" class="wp-caption aligncenter" style="width: 392px"><a href="http://www.rickigregersen.com/wp-content/uploads/custom_navbar.png"><img class="size-full wp-image-232" title="Custom UINavigationBar" src="http://www.rickigregersen.com/wp-content/uploads/custom_navbar.png" alt="Yes you are a pretty girl.." width="382" height="265" /></a><p class="wp-caption-text">The finished product</p></div>
<h3><strong>The caveats:</strong></h3>
<p>There are two different approaches involved: one is to build a category on the UINavigationBar, which is the view of the UINavigationController, to set the background to either a static color or a custom image. The other approach is to build a utility Class with one class method that alters the the look of a UIViewControllers UINavigationController. Notice that I wrote that we alter the look of the UINavigationController for each ViewController. There are caveats involved! This is just a Proof of Concept (feel free to add to the code and feel especially free to show me afterwards).</p>
<ul>
<li>It does not support rotation!</li>
<li>The size of the navigationBar buttons are fixed&#8217;!</li>
<li>The background color/image for the UINavigationBar can not be changed at runtime.</li>
<li>You need to implement a tap handler method to catch the actions from the buttons on the navigationBar.</li>
</ul>
<p><em>Probably other things… but it can be added and maybe it will.</em></p>
<h3><strong>The code:</strong></h3>
<p>First off, let&#8217;s construct a category for the UINavigationBar:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;UINavigationBar+customLook.h</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;UINavigationBarOverrideDrawRectPOC</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Ricki Gregersen on 14/6/10.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright 2010 www.rickigregersen.com. Use as you please:)</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import</span><br />
<br />
<span style="color: #a61390;">@interface</span> UINavigationBar <span style="color: #002200;">&#40;</span>customLook<span style="color: #002200;">&#41;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect;<br />
<span style="display:block;background-color:#ffff66"><br /></span><span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>And the implementation:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;UINavigationBar+customLook.h&quot;</span><br />
<br />
<span style="display:block;background-color:#ffff66"><span style="color: #a61390;">@implementation</span> UINavigationBar <span style="color: #002200;">&#40;</span>customLook<span style="color: #002200;">&#41;</span><br /></span><br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect <span style="color: #002200;">&#123;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">/* comment in this part to use a color instead of an image</span><br />
<span style="color: #11740a; font-style: italic;">&nbsp; &nbsp; UIColor *color = [UIColor redColor];</span><br />
<span style="color: #11740a; font-style: italic;">&nbsp; &nbsp; CGContextRef context = UIGraphicsGetCurrentContext();</span><br />
<span style="color: #11740a; font-style: italic;">&nbsp; &nbsp; CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));</span><br />
<span style="color: #11740a; font-style: italic;">&nbsp; &nbsp; CGContextFillRect(context, rect);</span><br />
<span style="color: #11740a; font-style: italic;">&nbsp; &nbsp; self.tintColor = [UIColor darkGrayColor];// color;</span><br />
<span style="color: #11740a; font-style: italic;">*/</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// comment out this part to use a color instead of an image</span><br />
&nbsp; &nbsp; UIImage <span style="color: #002200;">*</span>img&nbsp; &nbsp; <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;nav_bar_back.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>img drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, self.frame.size.width, self.frame.size.height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>The drawRect method is invoked every time a UIViewController is pushed onto the screen. You could therefore make global variable that held a reference to the image or color if you needed it to change at runtime.</p>
<p>Now onto the the UINavigaitonModifier Class. This contains one class method that takes a UIViewController, a title string for the left and right button, and a boolean for the left and right button determining if it is a square or an &#8220;arrow&#8221;. (the usual back button is an arrow). The class also defines a protocol for receiving actions when either button is tapped.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// &nbsp;ISNavigationModifier.h</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;UINavigationBarOverrideDrawRectPOC</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Ricki Gregersen on 14/6/10.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright 2010 www.rickigregersen.com. Use as you please:)</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import</span><br />
<br />
<span style="color: #a61390;">@protocol</span> ISNavigationModifierProtocol<br />
<br />
@optional<br />
<br />
<span style="display:block;background-color:#ffff66"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> leftBarButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender;<br /></span><span style="display:block;background-color:#ffff66"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> rightBarButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender;<br /></span><br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #a61390;">@interface</span> ISNavigationModifier <span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <span style="color: #002200;">&#123;</span><br />
<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="display:block;background-color:#ffff66"><span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> modifyNavigationBarFor<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIViewController<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> target <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> leftButtonString <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLeftArrow <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> rightButtonString <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isRightArrow;<br /></span><br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>The implementation:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// &nbsp;ISNavigationModifier.m</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;UINavigationBarOverrideDrawRectPOC</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Ricki Gregersen on 14/6/10.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright 2010 www.rickigregersen.com. Use as you please:)</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import &quot;ISNavigationModifier.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> ISNavigationModifier<br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> modifyNavigationBarFor<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIViewController<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> target <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> leftButtonString <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isLeftArrow <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> rightButtonString <span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> isRightArrow <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; UIButton <span style="color: #002200;">*</span>rightButton <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; UIButton <span style="color: #002200;">*</span>leftButton <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
<br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>leftButtonString<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br /></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; leftButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeCustom<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton addTarget<span style="color: #002200;">:</span>target action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>leftButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton.titleLabel setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Thonburi-Bold&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">12</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton setTitle<span style="color: #002200;">:</span>leftButtonString forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isLeftArrow<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 79.0f, 37.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;arrow_square_btn.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 79.0f, 37.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftButton setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;square_btn.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #002200;">&#125;</span><br />
<br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>rightButtonString<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br /></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rightButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeCustom<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton addTarget<span style="color: #002200;">:</span>target action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>rightButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton.titleLabel setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Thonburi-Bold&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">12</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton setTitle<span style="color: #002200;">:</span>rightButtonString forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isLeftArrow<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 79.0f, 37.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;arrow_square_btn.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 79.0f, 37.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightButton setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;square_btn.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/UILabel_Class/"><span style="color: #400080;">UILabel</span></a> <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/UILabel_Class/"><span style="color: #400080;">UILabel</span></a> alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0.0f, 0.0f, 150.0f, 20.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Thonburi-Bold&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">14</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label setTextAlignment<span style="color: #002200;">:</span>UITextAlignmentCenter<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label setText<span style="color: #002200;">:</span>target.title<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>target.navigationItem setTitleView<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label release<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; UIBarButtonItem <span style="color: #002200;">*</span>leftItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithCustomView<span style="color: #002200;">:</span>leftButton<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; UIBarButtonItem <span style="color: #002200;">*</span>rightItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem alloc<span style="color: #002200;">&#93;</span> initWithCustomView<span style="color: #002200;">:</span>rightButton<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>target.navigationItem setLeftBarButtonItem<span style="color: #002200;">:</span>leftItem<span style="color: #002200;">&#93;</span>;<br /></span><span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>target.navigationItem setRightBarButtonItem<span style="color: #002200;">:</span>rightItem<span style="color: #002200;">&#93;</span>;<br /></span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>leftItem release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>rightItem release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>The modifier class uses the reference to the UIViewController to change the navigationBar.</p>
<h3>Example:</h3>
<p>To use the above classes; put the UINavigationBar+customLook.h and UINavigationBar+customLook.m files somewhere in your project. Change the images or color property to fit your custom style.<br />
Also add the ISNavigationModifier.h and ISNavigationModifier.m.<br />
In a viewController that is pushed onto a NavigationController; import the ISNavigationModifier.h file, implement the methods: leftButtonHandler and rightButtonHandler.</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> viewDidLoad <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; self.title <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;I am a pretty girl&quot;</span>;<br />
<span style="display:block;background-color:#ffff66">&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>ISNavigationModifier modifyNavigationBarFor<span style="color: #002200;">:</span>self <span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Back&quot;</span> <span style="color: #002200;">:</span><span style="color: #a61390;">NO</span> <span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Next&quot;</span> <span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;<br /></span><span style="color: #002200;">&#125;</span><br />
<br />
<span style="display:block;background-color:#ffff66"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> leftButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender <span style="color: #002200;">&#123;</span><br /></span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController popViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Left Button Tapped!&quot;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<span style="display:block;background-color:#ffff66"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> rightButtonHandler<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender <span style="color: #002200;">&#123;</span><br /></span><br />
&nbsp; &nbsp; ISViewControllerThree <span style="color: #002200;">*</span>vcThree <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ISViewControllerThree alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ISViewControllerThree&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController pushViewController<span style="color: #002200;">:</span>vcThree animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>vcThree release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Right Button Tapped!&quot;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Feel free to put  rants, comments, questions and improvements in the comments below.    </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2010/06/16/customizing-the-uinavigationcontroller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>No More Virtual Machines</title>
		<link>http://www.rickigregersen.com/2010/01/17/no-more-virtual-machines/</link>
		<comments>http://www.rickigregersen.com/2010/01/17/no-more-virtual-machines/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 07:21:09 +0000</pubDate>
		<dc:creator>Ricki</dc:creator>
				<category><![CDATA[Objective C]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.rickigregersen.com/?p=224</guid>
		<description><![CDATA[Sorry for the 3 month dry streak. I was fired back in, think it was August? . I then had a three month &#8220;paid vaccination&#8221;(it was in my contract that in the event I was fired they had to pay me for 3 months but I didn&#8217;t have to come to work&#8230;sweet). Did some consulting [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the 3 month dry streak.</p>
<p>I was fired back in, think it was August? <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I then had a three month &#8220;paid vaccination&#8221;(it was in my contract that in the event I was fired they had to pay me for 3 months but I didn&#8217;t have to come to work&#8230;sweet). Did some consulting work, mostly to have something to do. Then I thought to my self that this was an excellent time to set a dream of mine in motion. I come from a background in computer and electronic engineering.</p>
<p>In my Flash/Java work I always had this strange feeling in the back of my head going &#8220;At some point this is going to break or perform strangely, and I have no way, other that trial and error, to figure out why&#8221;. This is harshly put, but I have been used to dealing with µControllers, the C language and copper-wire  for a long time and even though I appreciate things that &#8220;just work&#8221; as much as the next guy, I also feel the complete despair when it does not and you have no way of getting &#8220;under the hood&#8221;.</p>
<p>Im probably being ignorant and if I would I could sit down and read up on every nook and cranny of the runtime, then I would be the all-omnipotent, all-mighty and know-it-all master of&#8230; a nook.</p>
<p>My previous job involved building Flash apps for the AIR  runtime environment, I know, I know, that is asking for trouble(2007-2009), and my only real choice of an editor was Eclipse. Im a Mac user and that just &#8220;grinds my gears&#8221; to have to use some &#8220;lowest common denominator&#8221; GUI for what I do with most of the hours Im awake.</p>
<p>I have a duality in my that dictates that I love building stuff for the internal intricacies and that I only can enjoy software, furniture, food TV series etc. if I know the order and beauty that governs the inside also governs the outside, i.e. I like good design on both the inside and the outside.</p>
<p>So how do I get to work with µControllers and hardware, beautiful interfaces and have a set of development tools that doesn&#8217;t hate me and gives me a stack dump when I ask for it?</p>
<p><strong>I have become an iPhone developer!</strong></p>
<p>OK, plan&#8230; by rationing my means I can sustain myself for almost a year. In that timeframe I should be able to (a) learn Objective C (b) get a few apps in the store (c) go down new roads and be happy:)</p>
<p>So for the last three months I have been developing an app that will _blank_ for _blank_ when you go _blank_, with a designer called Mino, which is a secretive guy, hence the _blank_ <img src='http://www.rickigregersen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now we are close to a Beta version and I my head is exploding with pieces of info that I would like to put on the blog. Im at the state of learning a new language where I bought the first &#8220;pattern book&#8221;, which means I did a lot of <em>&#8220;ahh this seems to be the way to go&#8221; </em>only to go <em>&#8220;ahh so that is how I should have done it&#8221;</em> a few hours later. Well, to cut it short, I don&#8217;t think there will be a lot of AS &#8211; Java stuff on the blog in the time to come, but I hope to keep doing the visual experiments and give out some code snippets.</p>
<p>I&#8217;ll surely move on to building some Mac software afterwards, I like the tools, the Apple frameworks has the standard of the Apple hardware (95% perfect and 5% &#8220;WTF, this took me forever and now it&#8217;s broken again&#8221;) also I get the &#8220;complete package experience&#8221; that I was missing in my other endeavors.</p>
<p>So please spread the word that Im up for crazy and exciting projects, both here in DK and abroad.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rickigregersen.com/2010/01/17/no-more-virtual-machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
