<?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>iOS Developer Tips Blog &#187; User Interface</title>
	<atom:link href="http://iPhoneDeveloperTips.com/category/user-interface/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com</link>
	<description>iOS Developer Tips, Tricks and Tutorials.</description>
	<lastBuildDate>Wed, 08 Feb 2012 13:40:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>iOS 5 : Customize UINavigationBar and UIBarButtonItem with the Appearance API</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html#comments</comments>
		<pubDate>Mon, 02 Jan 2012 08:09:20 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=10815</guid>
		<description><![CDATA[In a previous post, UIImage and resizableImageWithCapInsets, I explained how to use the method resizableImageWithCapInsets in a UIImage object to set cap insets, which specify areas of an image that are not to be changed when resizing or scaling an image. That post was a segue to this post, which will use images (and cap [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous post, <a href="http://iphonedevelopertips.com/user-interface/ios-5-uiimage-and-resizableimagewithcapinsets.html" target="_blank">UIImage and resizableImageWithCapInsets</a>, I explained how to use the method <strong>resizableImageWithCapInsets</strong> in a <strong>UIImage</strong> object to set cap insets, which specify areas of an image that are not to be changed when resizing or scaling an image. That post was a segue to this post, which will use images (and cap insets) as part of the iOS 5 appearance API and customizing the navigation bar.</p>
<h5>Change UINavigationBar Background</h5>
<p>With the release of iOS 5, the <strong>UIAppearance</strong> protocol is used to access the appearance proxy for a class you would like to configure. Customization is done by sending messages to the target class appearance proxy. When changing the appearance of an object, all instances of the object can be updated or only specific instances within a container class.</p>
<p>Let&#8217;s see how this looks as it relates to updating the background color of a <strong>UINavigationBar</strong>, it&#8217;s text and the back button which will allow a user to return to a previous view controller.<br />
<span id="more-10815"></span></p>
<p>The image below is the gradient that I will use for the background:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/BlueGradientBackground.png" alt="" title="BlueGradientBackground" width="54" height="51" class="alignnone size-full wp-image-10819" /></p>
<p>Using the above image, I created a one pixel wide image for both portrait and landscape variations of the navbar, reason being, the height of the navar bar when the device is in portrait mode is 44, whereas the height for landscape is 32.</p>
<p>The images in my project are NavigationPortraitBackground.png and NavigationLandscapeBackground.png, both shown below:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/NavigationPortraitBackground.png" alt="" title="NavigationPortraitBackground" width="1" height="44" class="alignnone size-full wp-image-10822" /></p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/NavigationLandscapeBackground.png" alt="" title="NavigationLandscapeBackground" width="1" height="32" class="alignnone size-full wp-image-10837" /></p>
<p>I now create two <strong>UIImage</strong> objects:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Create image for navigation background - portrait</span>
UIImage <span style="color: #002200;">*</span>NavigationPortraitBackground <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;NavigationPortraitBackground&quot;</span><span style="color: #002200;">&#93;</span> 
                              resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create image for navigation background - landscape</span>
UIImage <span style="color: #002200;">*</span>NavigationLandscapeBackground <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;NavigationLandscapeBackground&quot;</span><span style="color: #002200;">&#93;</span> 
                              resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>To set these images as the new backgrounds for all navigation bars, here&#8217;s all I need to do:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Set the background image all UINavigationBars</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationBar appearance<span style="color: #002200;">&#93;</span> setBackgroundImage<span style="color: #002200;">:</span>NavigationPortraitBackground 
                                     forBarMetrics<span style="color: #002200;">:</span>UIBarMetricsDefault<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationBar appearance<span style="color: #002200;">&#93;</span> setBackgroundImage<span style="color: #002200;">:</span>NavigationLandscapeBackground 
                                     forBarMetrics<span style="color: #002200;">:</span>UIBarMetricsLandscapePhone<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In addition to the color, I can change the appearance of the text on all navigations bars as well:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Set the text appearance for navbar</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationBar appearance<span style="color: #002200;">&#93;</span> setTitleTextAttributes<span style="color: #002200;">:</span>
    <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span>
    <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>, UITextAttributeTextColor, 
    <span style="color: #002200;">&#91;</span>UIColor redColor<span style="color: #002200;">&#93;</span>, UITextAttributeTextShadowColor, 
    <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithUIOffset<span style="color: #002200;">:</span>UIOffsetMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>, UITextAttributeTextShadowOffset, 
    <span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Verdana-Bold&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">16</span><span style="color: #002200;">&#93;</span>, UITextAttributeFont, 
    <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>As the final step, I will update the back button with a custom image, which is shown below (the button is shown on a gray backdrop so you can see the white border):</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/blueButton.gif" alt="" title="blueButton" width="121" height="60" class="alignnone size-full wp-image-10771" /></p>
<p>Using what I described in the early post about cap insets, I can create a <strong>UIImage</strong> object and use the appearance API of the <strong>UIBarButtonItem</strong> to set the back button look. Notice that each value in the cap inset is set to 12, indicating all four corners are to hold steady at 12 pixels, even if the images stretched or resized.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Set back button for navbar</span>
UIImage <span style="color: #002200;">*</span>backButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blueButton&quot;</span><span style="color: #002200;">&#93;</span>  resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIBarButtonItem appearance<span style="color: #002200;">&#93;</span> setBackButtonBackgroundImage<span style="color: #002200;">:</span>backButton forState<span style="color: #002200;">:</span>UIControlStateNormal barMetrics<span style="color: #002200;">:</span>UIBarMetricsDefault<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The last step is to create a button for the user interface that will push a new view controller, which will update the navigation bar to show the custom back button created above.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">...
&nbsp;
testButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80</span>, <span style="color: #2400d9;">30</span>, <span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;  
<span style="color: #002200;">&#91;</span>testButton setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Test Button&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Notice cap insets are different from above</span>
UIImage <span style="color: #002200;">*</span>buttonImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blueButton&quot;</span><span style="color: #002200;">&#93;</span>  resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">16</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">16</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>testButton addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span> UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;        
<span style="color: #002200;">&#91;</span>testButton setBackgroundImage<span style="color: #002200;">:</span>buttonImage forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
&nbsp;
...</pre></div></div>

<p>An important concept to understand here, I&#8217;ve used the same image, blueButton.png, for both the custom back button as well as the button on the primary user interface &#8211; setting the cap insets specifies the rules, if you will, of how the image can be stretched, yet keep the look appropriate for the context in which the button will appear (that is, on the navbar or main UI).</p>
<p>A few screenshots follow that show the custom navigation bar, text and buttons in both portrait and landscape modes:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/navbar1.png" alt="" title="navbar1" width="340" height="160" class="alignnone size-full wp-image-10834" /></p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/navbar2.png" alt="" title="navbar2" width="340" height="120" class="alignnone size-full wp-image-10833" /></p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/navbar3.png" alt="" title="navbar3" width="500" height="160" class="alignnone size-full wp-image-10832" /></p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/navbar4.png" alt="" title="navbar4" width="500" height="110" class="alignnone size-full wp-image-10831" /></p>
<h5>Download the Xcode Project</h5>
<p>You can download the entire project source code <a href="http://iPhoneDeveloperTips.com/wp-content/uploads/2012/01/CustomNavbar.zip">here</a>.</p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iOS 5 : UIImage and resizableImageWithCapInsets</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/ios-5-uiimage-and-resizableimagewithcapinsets.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/ios-5-uiimage-and-resizableimagewithcapinsets.html#comments</comments>
		<pubDate>Tue, 20 Dec 2011 07:02:10 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=10765</guid>
		<description><![CDATA[I recently began writing a short example to learn more about the iOS 5 Appearance API and customizing UINavigationBar objects. The goal was to add a custom background, title and text to the navbar. Once I had this working, to keep a consist look across my application, I began tweaking the buttons on the navbar [...]]]></description>
			<content:encoded><![CDATA[<p>I recently began writing a short example to learn more about the iOS 5 Appearance API and customizing <strong>UINavigationBar</strong> objects. The goal was to add a custom background, title and text to the navbar. Once I had this working, to keep a consist look across my application, I began tweaking the buttons on the navbar using the same Appearance API.</p>
<p>As I got further into the customization of the buttons, I ran into a method within <strong>UIImage</strong> that was introduced in iOS 5, <strong>resizableImageWithCapInsets</strong>. I found myself getting side-tracked from the original idea of navbar look and feel, to understanding how cap insets work. This post delves into what I learned.<br />
<span id="more-10765"></span></p>
<h5>Cap Insets with UIButton</h5>
<p>As the documentation describes, you use <strong>resizableImageWithCapInsets</strong> to add cap insets to an image, when the image is resized or scaled, cap areas are not affected. The best way to understand this is through an example.</p>
<p>Let&#8217;s assume I want all the buttons on my UI to have a similar look, a gradient with a white border. Below is the image used for the examples in this post (the button is shown on a gray backdrop so you can see the white border):</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/blueButton.gif" alt="" title="blueButton" width="121" height="60" class="alignnone size-full wp-image-10771" /></p>
<p>Depending on the context of where the button appears, its size may vary. The code to create a button with the image and the corresponding output follow:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIButton <span style="color: #002200;">*</span>button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80</span>, <span style="color: #2400d9;">130</span>, <span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;  
<span style="color: #002200;">&#91;</span>button setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Test Button&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Image with without cap insets</span>
UIImage <span style="color: #002200;">*</span>buttonImage <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;blueButton&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span> UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;        
<span style="color: #002200;">&#91;</span>button setBackgroundImage<span style="color: #002200;">:</span>buttonImage forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/button0.gif" alt="" title="button0" width="238" height="76" class="alignnone size-full wp-image-10767" /></p>
<p>As you can see, the button is stretched in all directions. Let&#8217;s change the code to include cap insets, however, before we do that, let&#8217;s look at the signature of the cap insets method:</p>
<p>- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets</p>
<p>Looking on step further, <strong>UIEdgeInserts</strong> is defined as:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">struct</span> <span style="color: #002200;">&#123;</span>
   CGFloat top, left, bottom, right;
<span style="color: #002200;">&#125;</span> UIEdgeInsets;</pre></div></div>

<p><strong>UIEdgeInsets</strong> is structure that specifies float values for each cap inset: top, left, bottom and right areas of an image. To apply this to the image for the button, here is all we need to do:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Image with cap insets</span>
UIImage <span style="color: #002200;">*</span>buttonImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blueButton&quot;</span><span style="color: #002200;">&#93;</span>  
   resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">16</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">16</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This requests that the left and right 16 pixels of the original image are not scaled or resized when stretching the image to accomodate the button size frame defined above. The end results is as shown below:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/button1.gif" alt="" title="button1" width="239" height="76" class="alignnone size-full wp-image-10768" /></p>
<h5>Cap Insets with UIBarButtonItem</h5>
<p>We can use the same image for a button on a navbar (I&#8217;ll show the specifics in the next post on customizing the navbar). Without specifying the cap insets, the button looks as follows:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/backButton0.gif" alt="" title="backButton0" width="340" height="80" class="alignnone size-full wp-image-10778" /></p>
<p>The code below specifies an image where 12 pixels on the top, left, bottom and right be preserved when stretching/resizing the button:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIImage <span style="color: #002200;">*</span>backButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blueButton&quot;</span><span style="color: #002200;">&#93;</span>  
   resizableImageWithCapInsets<span style="color: #002200;">:</span>UIEdgeInsetsMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span>, <span style="color: #2400d9;">12</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The output nows looks as follows:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/12/backButton1.gif" alt="" title="backButton1" width="340" height="80" class="alignnone size-full wp-image-10779" /></p>
<h5>Next Post</h5>
<p>With that under our belt, in the next post I&#8217;ll continue with my original idea of customizing <strong>UINavigationBar</strong>, including background, title and text, as well as the buttons on the navbar.</p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/ios-5-uiimage-and-resizableimagewithcapinsets.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>iOS 5 : UIStepper Control</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/ios-5-uistepper-control.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/ios-5-uistepper-control.html#comments</comments>
		<pubDate>Wed, 02 Nov 2011 07:01:05 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=10533</guid>
		<description><![CDATA[There is a new pre-built control in iOS 5 for incrementing or decrementing a value, UIStepper. The control has two buttons aligned horizontally, one labeled with a plus (+) the other a minus (-). One nice feature is a continuous option, wherein if the user presses and holds down either +/- button, the stepper value [...]]]></description>
			<content:encoded><![CDATA[<p>There is a new pre-built control in iOS 5 for incrementing or decrementing a value, <strong>UIStepper</strong>. The control has two buttons aligned horizontally, one labeled with a plus (+) the other a minus (-). </p>
<p>One nice feature is a continuous option, wherein if the user presses and holds down either +/- button, the stepper value is incremented repeatedly. The longer the button is held down, the faster the increment will occur. Also, you can have the increment value wrap around when a range of values is specified, for example, if you set min and max to 0 and 99 respectively, when the value reaches 99, the next value will be 0 (and vice-versa).<br />
<span id="more-10533"></span></p>
<p>Below is a screenshot that shows the output of the example code below:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/11/stepper.gif" alt="" title="stepper" width="338" height="92" class="alignnone size-full wp-image-10535" /></p>
<p>Below is a short code example showing the various properties available in <strong>UIStepper</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  <span style="color: #11740a; font-style: italic;">// Create a label to show the value in the stepper</span>
  label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">100</span>, <span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;    
  <span style="color: #002200;">&#91;</span>label setTextColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
  <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>;
  <span style="color: #002200;">&#91;</span>label setTextAlignment<span style="color: #002200;">:</span>UITextAlignmentLeft<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>label setText<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Quantity:&quot;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Frame defines location, size values are ignored</span>
  UIStepper <span style="color: #002200;">*</span>stepper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIStepper alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">120</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;    
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Set action target and action for a particular value changed event</span>
  <span style="color: #002200;">&#91;</span>stepper addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>stepperPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventValueChanged<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Set min and max</span>
  <span style="color: #002200;">&#91;</span>stepper setMinimumValue<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>stepper setMaximumValue<span style="color: #002200;">:</span><span style="color: #2400d9;">99</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Value wraps around from minimum to maximum</span>
  <span style="color: #002200;">&#91;</span>stepper setWraps<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// If continuos (default), changes are sent for each change in stepper,</span>
  <span style="color: #11740a; font-style: italic;">// otherwise, change event occurs once user lets up on button</span>
  <span style="color: #002200;">&#91;</span>stepper setContinuous<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// To change the increment value for each step</span>
  <span style="color: #11740a; font-style: italic;">// (default is 1)</span>
  <span style="color: #002200;">&#91;</span>stepper setStepValue<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/ios-5-uistepper-control.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simple Menus and Messages with UIActionSheet</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/simple-menus-and-messages-with-uiactionsheet.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/simple-menus-and-messages-with-uiactionsheet.html#comments</comments>
		<pubDate>Mon, 10 Oct 2011 06:21:24 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=10361</guid>
		<description><![CDATA[If you need to create a quick menu or present a user with a short message, you may want to consider a UIActionSheet as an option. This control will slide up from the bottom of the screen, and offers a number of easily configurable options. The code in the interface definition below creates an actionsheet [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to create a quick menu or present a user with a short message, you may want to consider a <strong>UIActionSheet</strong> as an option. This control will slide up from the bottom of the screen, and offers a number of easily configurable options.</p>
<p>The code in the interface definition below creates an actionsheet (if you prefer, you can accomplish the same using Interface Builder to layout and define a UIActionSheet). Notice there is a delegate required if you define multiple buttons on the sheet and need to determine which was tapped:<br />
<span id="more-10361"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> SandboxViewController <span style="color: #002200;">:</span> UIViewController &lt;UIActionSheetDelegate&gt;
<span style="color: #002200;">&#123;</span>
  ...
  UIActionSheet <span style="color: #002200;">*</span>sheet;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>At some point in your code you can create a sheet as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  sheet <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActionSheet alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Select Belgian Beer Style&quot;</span>
                                      delegate<span style="color: #002200;">:</span>self
                             cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cancel&quot;</span>
                       destructiveButtonTitle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
                            otherButtonTitles<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Dubble&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lambic&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Quadrupel&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Strong Dark Ale&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tripel&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Show the sheet</span>
  <span style="color: #002200;">&#91;</span>sheet showInView<span style="color: #002200;">:</span>self.view<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>sheet release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Here is another variation:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  sheet <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActionSheet alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Select Account to Delete&quot;</span>
                                      delegate<span style="color: #002200;">:</span>self
                             cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cancel&quot;</span>
                        destructiveButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Delete All Accounts&quot;</span>
                             otherButtonTitles<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Checking&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Savings&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Money Market&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #11740a; font-style: italic;">// Show the sheet</span>
  <span style="color: #002200;">&#91;</span>sheet showInView<span style="color: #002200;">:</span>self.view<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>sheet release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The screenshots below show each of the above sheets and how they look on the simulator:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/10/actionsheet1.gif" alt="" title="actionsheet1" width="488" height="360" class="alignnone size-full wp-image-10363" /></p>
<p>To determine which button was selected, implement the method shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>actionSheet<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIActionSheet <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>actionSheet didDismissWithButtonIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>buttonIndex
<span style="color: #002200;">&#123;</span>
  NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Button %d&quot;</span>, buttonIndex<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>One additional way to use an actionsheet is to present information to a user, in this case, you fill in the title and just one button:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  sheet <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActionSheet alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor....&quot;</span>
                                      delegate<span style="color: #002200;">:</span>self
                             cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
                        destructiveButtonTitle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span>
                             otherButtonTitles<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Got it.&quot;</span> ,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Show the sheet</span>
  <span style="color: #002200;">&#91;</span>sheet showInView<span style="color: #002200;">:</span>self.view<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>sheet release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/10/actionsheet2.gif" alt="" title="actionsheet2" width="240" height="360" class="alignnone size-full wp-image-10364" /></p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/simple-menus-and-messages-with-uiactionsheet.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Load and Access Custom Fonts</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/load-and-access-custom-fonts.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/load-and-access-custom-fonts.html#comments</comments>
		<pubDate>Mon, 18 Jul 2011 07:12:56 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=9031</guid>
		<description><![CDATA[It&#8217;s surprisingly easy to add custom fonts to your iOS apps. Begin by adding the font(s) to your project, (drag/drag into the resources folder in the Project Window). Next, add a property in the project plist named UIAppFonts, which is an array containing the names of each font you would like to make available in [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s surprisingly easy to add custom fonts to your iOS apps. Begin by adding the font(s) to your project, (drag/drag into the resources folder in the Project Window).</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/07/fonts1.png" alt="" width="243" height="70" /><br />
<span id="more-9031"></span></p>
<p>Next, add a property in the project plist named <strong>UIAppFonts</strong>, which is an array containing the names of each font  you would like to make available in the application &#8211; if you are using the Property List Editor in Xcode, select <strong>Fonts provided by application</strong> from the dropdown list. Add an entry for each font:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/07/fonts2.png" alt="" width="401" height="60" /></p>
<p>The property list below is the text version of the plist file, here you can see the key <strong>UIAppFonts</strong>, the array and each of the two font entries:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/07/fonts3.png" alt="" width="263" height="72" /></p>
<p>To access the fonts within an application, call the method <strong>fontWithName</strong> in the <strong>UIFont</strong> class, include the font size as well:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UILabel <span style="color: #002200;">*</span>label1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">30</span>, <span style="color: #2400d9;">240</span>, <span style="color: #2400d9;">40</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>label1 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;Grinched&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">24</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>label1 setText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Grinched Font&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>label1<span style="color: #002200;">&#93;</span>;  
&nbsp;
UILabel <span style="color: #002200;">*</span>label2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">80</span>, <span style="color: #2400d9;">240</span>, <span style="color: #2400d9;">40</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>label2 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;Energon&quot;</span> size<span style="color: #002200;">:</span><span style="color: #2400d9;">18</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>label2 setText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Energon Font&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>label2<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The output of the above looks as follows in the simulator:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2011/07/fonts4.png" alt="" width="338" height="155" /></p>
<p>To get a list of all the available font family names in your app, add this to your code:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Available fonts: %@&quot;</span>, <span style="color: #002200;">&#91;</span>UIFont familyNames<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/load-and-access-custom-fonts.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Font Macros for Consistency</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/using-font-macros-for-consistency.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/using-font-macros-for-consistency.html#comments</comments>
		<pubDate>Wed, 06 Jul 2011 11:03:35 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=8861</guid>
		<description><![CDATA[In most applications, keeping with one or two fonts is a good design choice. To this end, I often include a few simple macros to keep fonts consistent, easily change font size as well as emphasis (bold). Below are a few macros that give you an idea how I might go about specifying two primary [...]]]></description>
			<content:encoded><![CDATA[<p>In most applications, keeping with one or two fonts is a good design choice. To this end, I often include a few simple macros to keep fonts consistent, easily change font size as well as emphasis (bold).</p>
<p>Below are a few macros that give you an idea how I might go about specifying two primary fonts for an app:<br />
<span id="more-8861"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// For text, messages, etc</span>
<span style="color: #6e371a;">#define DEFAULT_FONTSIZE    15</span>
<span style="color: #6e371a;">#define DEFAULT_FONT(s)     [UIFont fontWithName:@&quot;ArialMT&quot; size:s]</span>
<span style="color: #6e371a;">#define DEFAULT_BOLDFONT(s) [UIFont fontWithName:@&quot;Arial-BoldMT&quot; size:s]</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// For table cells</span>
<span style="color: #6e371a;">#define CELL_FONTSIZE    16</span>
<span style="color: #6e371a;">#define CELL_FONT(s)     [UIFont fontWithName:@&quot;Helvetica-Oblique&quot; size:s]</span>
<span style="color: #6e371a;">#define CELL_BOLDFONT(s) [UIFont fontWithName:@&quot;Helvetica-BoldOblique&quot; size:s]</span></pre></div></div>

<p>With these macros in defined it is easy to specify fonts based on where they are used and keep things consistent across an app:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Assume textFieldUserName is a UITextField</span>
<span style="color: #002200;">&#91;</span>textFieldUserName setFont<span style="color: #002200;">:</span>DEFAULT_FONT<span style="color: #002200;">&#40;</span>DEFAULT_FONTSIZE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// For bold and larger text</span>
<span style="color: #002200;">&#91;</span>someTextField setFont<span style="color: #002200;">:</span>DEFAULT_BOLDFONT<span style="color: #002200;">&#40;</span>DEFAULT_FONTSIZE <span style="color: #002200;">+</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
...
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set cell font sizes</span>
<span style="color: #11740a; font-style: italic;">// Assume cell is a UITableViewCell</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>cell textLabel<span style="color: #002200;">&#93;</span> setFont<span style="color: #002200;">:</span>CELL_FONT<span style="color: #002200;">&#40;</span>CELL_FONTSIZE<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// For bold and larger text</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>cell textLabel<span style="color: #002200;">&#93;</span> setFont<span style="color: #002200;">:</span>CELL_BOLDFONT<span style="color: #002200;">&#40;</span>CELL_FONTSIZE <span style="color: #002200;">+</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>You could also add a few additional macros for fonts that support italics or other attributes. If you have similar macros, please feel free to share in the comments section.</p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/using-font-macros-for-consistency.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Deselect Table Row with Animation</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/deselect-table-row-with-animation.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/deselect-table-row-with-animation.html#comments</comments>
		<pubDate>Mon, 13 Jun 2011 07:27:16 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=8693</guid>
		<description><![CDATA[Here is a quick little trick to automatically deselect a table row once tapped by a user. With the approach below you can also adjust the length of the delay (in seconds) before the deselection occurs. When working with a table, when a row is selected didSelectRowAtIndexPath is called, inside this method after you take [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick little trick to automatically deselect a table row once tapped by a user. With the approach below you can also adjust the length of the delay (in seconds) before the deselection occurs.</p>
<p>When working with a table, when a row is selected <strong>didSelectRowAtIndexPath</strong> is called, inside this method after you take care of any other business, call <strong>performSelector</strong> specifying a method to call and a delay. In the called method simply deselect the table row as shown below:<br />
<span id="more-8693"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> unselectCurrentRow
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Animate the deselection</span>
  <span style="color: #002200;">&#91;</span>self.tableView deselectRowAtIndexPath<span style="color: #002200;">:</span>
      <span style="color: #002200;">&#91;</span>self.tableView indexPathForSelectedRow<span style="color: #002200;">&#93;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView 
      didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newIndexPath
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Any other table management you need</span>
  ...
&nbsp;
  <span style="color: #11740a; font-style: italic;">// After one second, unselect the current row</span>
  <span style="color: #002200;">&#91;</span>self performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>unselectCurrentRow<span style="color: #002200;">&#41;</span> 
      withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> afterDelay<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/deselect-table-row-with-animation.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating Clickable Hyperlinks from a URL, Phone Number or Address</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html#comments</comments>
		<pubDate>Mon, 22 Nov 2010 03:12:59 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=7040</guid>
		<description><![CDATA[The following tips shows a quick way to create clickable hyperlinks using a UITextView. The trick is to set the dataDetectorTypes property to specify the data type you are after, from there, upon a tap the link will launch the appropriate application, namely Safari, Phone Dialer or Maps. Clickable URL 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>The following tips shows a quick way to create clickable hyperlinks using a UITextView. The trick is to set the <strong>dataDetectorTypes</strong> property to specify the data type you are after, from there, upon a tap the link will launch the appropriate application, namely Safari, Phone Dialer or Maps.</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/11/links.png" alt="" width="346" height="152" /><br />
<span id="more-7040"></span></p>
<h5>Clickable URL</h5>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Create textview, centering horizontally</span>
UITextView <span style="color: #002200;">*</span>textView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITextView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">10</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">50</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set font, background and alignment</span>
<span style="color: #002200;">&#91;</span>textView setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">16</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>textView setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>textView setTextAlignment<span style="color: #002200;">:</span>UITextAlignmentCenter<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Unfortunately the link will show as blue even with this setting</span>
<span style="color: #11740a; font-style: italic;">//  [textView setTextColor:[UIColor greenColor]];</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Edit and scrolling off  </span>
<span style="color: #002200;">&#91;</span>textView setEditable<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>textView setScrollEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set data type to specify URL/link</span>
<span style="color: #002200;">&#91;</span>textView setDataDetectorTypes<span style="color: #002200;">:</span>UIDataDetectorTypeLink<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set text as URL</span>
<span style="color: #002200;">&#91;</span>textView setText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;iOSDeveloperTips.com&quot;</span><span style="color: #002200;">&#93;</span>;  
&nbsp;
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>textView<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<h5>Clickable Phone Number</h5>
<p>To change up the code to support a clickable phone number, replace lines 16-21 with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Set data type to phone number</span>
<span style="color: #002200;">&#91;</span>textView setDataDetectorTypes<span style="color: #002200;">:</span>UIDataDetectorTypePhoneNumber<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set text as phone number</span>
<span style="color: #002200;">&#91;</span>textView setText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;800-555-1212&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h5>Clickable Address</h5>
<p>With the release of iOS 4.0, you can now create a clickable address. Tapping on the link will launch the Maps application.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Set data type to address</span>
<span style="color: #002200;">&#91;</span>textView setDataDetectorTypes<span style="color: #002200;">:</span>UIDataDetectorTypeAddress<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Set text as phone number</span>
<span style="color: #002200;">&#91;</span>textView setText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;1 Infinite Loop, Cupertino, CA 95014&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Circular and Infinite UIScrollViews</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html#comments</comments>
		<pubDate>Fri, 05 Nov 2010 07:09:21 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=7020</guid>
		<description><![CDATA[Editor&#8217;s Note: This post was written by Jacob Haskins, Director of Mobile Development at Accella. Thanks to Jon Stroz of Accella for reaching out to me to share this idea. When creating paging functionality for iPhone apps, there may be times that an infinite page loop would be desired. For example, if you have a [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Editor&#8217;s Note:</strong> This post was written by Jacob Haskins, Director of Mobile Development at <a href="http://www.accella.net" target="_blank">Accella</a>. Thanks to Jon Stroz of Accella for reaching out to me to share this idea.<br />
</em></p>
<p>When creating paging functionality for iPhone apps, there may be times that an infinite page loop would be desired. For example, if you have a small gallery of photos you are displaying, you may want to swipe through the set and have it start back at the beginning once you reach the end. The user would be able to continue swiping as much as they wanted in one direction to continue to view the content. Here are two strategies for achieving this result:<br />
<span id="more-7020"></span></p>
<h5>Duplicate End Caps</h5>
<p>The first option is best suited for smaller loops. Suppose you have ten photos to display. When the user is on photo one and swipes left, it will take the user to photo ten. When the user is on photo ten and swipes right, it will take the user to photo one. The logic we will follow here is to add photos in order, but place an duplicate of photo ten to the left of photo one and a duplicate of photo one to the right of photo ten.</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/11/scrollingInfiniteLoop1.jpg" alt="" width="598" height="126" /></p>
<p>Now when the user scrolls to the end, we reposition the content offset of our UIScrollView. By having a duplicate photo at the end and repositioning the offset without using animation, we create a seamless experience for the user.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>scrollViewDidEndDecelerating<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIScrollView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sender 
<span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// The key is repositioning without animation</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>scrollView.contentOffset.x <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// user is scrolling to the left from image 1 to image 10.</span>
        <span style="color: #11740a; font-style: italic;">// reposition offset to show image 10 that is on the right in the scroll view</span>
        <span style="color: #002200;">&#91;</span>scrollView scrollRectToVisible<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">3520</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">480</span><span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>scrollView.contentOffset.x <span style="color: #002200;">==</span> <span style="color: #2400d9;">3840</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// user is scrolling to the right from image 10 to image 1.</span>
        <span style="color: #11740a; font-style: italic;">// reposition offset to show image 1 that is on the left in the scroll view</span>
        <span style="color: #002200;">&#91;</span>scrollView scrollRectToVisible<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">480</span><span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>3 Pages Only</h5>
<p>There may be times when you want an infinite page loop, but don&#8217;t want to load in a lot of content. For example, You may have a lot of content to display inside the UIScrollView. Loading large amounts of data there would not be the ideal approach to the situation. </p>
<p>The logic that we can use there is to keep the UIScrollView at just three pages. Data would load on each page and the user would always be looking at the data in the middle page. When the user scrolled to a new page, the content for each page would be reset and the offset would go back the user is back to viewing the middle page. That way even though you may have a large amount of data to scroll through, it&#8217;s not all loaded at once. Only three pages are ever loaded at one time.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<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>
  <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
&nbsp;
  documentTitles <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// create our array of documents</span>
  <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">10</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>documentTitles addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Document %i&quot;</span>,i<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// create placeholders for each of our documents</span>
  pageOneDoc <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  pageTwoDoc <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  pageThreeDoc <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">640</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">44</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  pageOneDoc.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;
  pageTwoDoc.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;
  pageThreeDoc.textAlignment <span style="color: #002200;">=</span> UITextAlignmentCenter;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// load all three pages into our scroll view</span>
  <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span><span style="color: #2400d9;">9</span> onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #002200;">&#91;</span>scrollView addSubview<span style="color: #002200;">:</span>pageOneDoc<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>scrollView addSubview<span style="color: #002200;">:</span>pageTwoDoc<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>scrollView addSubview<span style="color: #002200;">:</span>pageThreeDoc<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// adjust content size for three pages of data and reposition to center page</span>
  scrollView.contentSize <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">960</span>, <span style="color: #2400d9;">416</span><span style="color: #002200;">&#41;</span>;
  <span style="color: #002200;">&#91;</span>scrollView scrollRectToVisible<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">416</span><span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadPageWithId<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>index onPage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>page 
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// load data for page</span>
  <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>page<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">case</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">:</span>
      pageOneDoc.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentTitles objectAtIndex<span style="color: #002200;">:</span>index<span style="color: #002200;">&#93;</span>;
      <span style="color: #a61390;">break</span>;
    <span style="color: #a61390;">case</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">:</span>
      pageTwoDoc.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentTitles objectAtIndex<span style="color: #002200;">:</span>index<span style="color: #002200;">&#93;</span>;
      <span style="color: #a61390;">break</span>;
    <span style="color: #a61390;">case</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">:</span>
      pageThreeDoc.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentTitles objectAtIndex<span style="color: #002200;">:</span>index<span style="color: #002200;">&#93;</span>;
      <span style="color: #a61390;">break</span>;
  <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>scrollViewDidEndDecelerating<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIScrollView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sender 
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// All data for the documents are stored in an array (documentTitles).</span>
  <span style="color: #11740a; font-style: italic;">// We keep track of the index that we are scrolling to so that we</span>
  <span style="color: #11740a; font-style: italic;">// know what data to load for each page.</span>
  <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>scrollView.contentOffset.x &gt; scrollView.frame.size.width<span style="color: #002200;">&#41;</span> 
  <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// We are moving forward. Load the current doc data on the first page.</span>
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>currIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Add one to the currentIndex or reset to 0 if we have reached the end.</span>
    currIndex <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>currIndex $gt;<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentTitles count<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> ? <span style="color: #2400d9;">0</span> <span style="color: #002200;">:</span> currIndex <span style="color: #002200;">+</span> <span style="color: #2400d9;">1</span>;
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>currIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Load content on the last page. This is either from the next item in the array</span>
    <span style="color: #11740a; font-style: italic;">// or the first if we have reached the end.</span>
    nextIndex <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>currIndex $gt;<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentTitles count<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> ? <span style="color: #2400d9;">0</span> <span style="color: #002200;">:</span> currIndex <span style="color: #002200;">+</span> <span style="color: #2400d9;">1</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>nextIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
  <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>scrollView.contentOffset.x $lt; scrollView.frame.size.width<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// We are moving backward. Load the current doc data on the last page.</span>
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>currIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Subtract one from the currentIndex or go to the end if we have reached the beginning.</span>
    currIndex <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>currIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> ? <span style="color: #002200;">&#91;</span>documentTitles count<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">:</span> currIndex <span style="color: #002200;">-</span> <span style="color: #2400d9;">1</span>;
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>currIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Load content on the first page. This is either from the prev item in the array</span>
    <span style="color: #11740a; font-style: italic;">// or the last if we have reached the beginning.</span>
    prevIndex <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>currIndex <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> ? <span style="color: #002200;">&#91;</span>documentTitles count<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">:</span> currIndex <span style="color: #002200;">-</span> <span style="color: #2400d9;">1</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>self loadPageWithId<span style="color: #002200;">:</span>prevIndex onPage<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>     
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Reset offset back to middle page</span>
  <span style="color: #002200;">&#91;</span>scrollView scrollRectToVisible<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">416</span><span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>Download the Source Code</h5>
<p><a href="http://iphonedevelopertips.com/wp-content/uploads/2010/11/CircularScrollView.zip">Xcode Project &#8211; Circular UI Scrollview</a></p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Screen Capture using UIGetScreenImage</title>
		<link>http://iPhoneDeveloperTips.com/user-interface/screen-capture-using-uigetscreenimage.html</link>
		<comments>http://iPhoneDeveloperTips.com/user-interface/screen-capture-using-uigetscreenimage.html#comments</comments>
		<pubDate>Mon, 10 May 2010 11:36:23 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6202</guid>
		<description><![CDATA[Editor&#8217;s Note: I read today (7/22/2010) that Apple is no longer approving applications using UIGetScreenImage. I haven&#8217;t been able to find an official Apple announcement on this &#8211; however, please give this consideration before using this method in your apps. As talked about on TUAW, among other popular blogs, Apple has opened up the API [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Editor&#8217;s Note:</strong> I read today (7/22/2010) that Apple is no longer approving applications using UIGetScreenImage. I haven&#8217;t been able to find an official Apple announcement on this &#8211; however, please give this consideration before using this method in your apps.</em></p>
<p>As talked about on <a  target="_blank"  href="http://www.tuaw.com/2009/12/15/apple-relents-and-is-now-allowing-uigetscreenimage-for-app-st/">TUAW</a>, among other popular blogs, Apple has opened up the API to allow applications to capture the screen contents. So what&#8217;s the excitement all about? Read on, as this method opens up some interesting possibilities&#8230;<br />
<span id="more-6202"></span></p>
<p>One of the unique opportunities is capturing screen contents while the camera is active, think augmented reality. One example of this idea in action is <a  target="_blank"  href="http://sudokugrab.blogspot.com/">Sudoku Grab</a> created by Chris Greening. The application allows the user to point the camera to a Sudoko board wherein the app will recognize the board, process the information and (optionally) show the solution. It&#8217;s not so much about solving the game that&#8217;s interesting as is the idea of using <strong>UIGetScreenImage()</strong> as a means to make this happen.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/wt96OomJY9A&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wt96OomJY9A&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<h5>Setting up the User Interface</h5>
<p>So let&#8217;s look at how to call <strong>UIGetScreenImage()</strong> to capture screen contents. This app consists of one primary view controller, the initialization is shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init
<span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
  <span style="color: #002200;">&#123;</span>
    self.view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> applicationFrame<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
		self.view.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor grayColor<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Button to activate camera</span>
    button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80</span>, <span style="color: #2400d9;">55</span>, <span style="color: #2400d9;">162</span>, <span style="color: #2400d9;">53</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;    
    <span style="color: #002200;">&#91;</span>button 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;Camera.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span> UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;      
    <span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>button release<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #a61390;">return</span> self;  
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This simple UI presents nothing more than one button, which when pressed will call a method to activate <strong>UIGetScreenImage()</strong> to capture the screen.</p>
<h5>Calling UIGetScreenImage()</h5>
<p>Before we can call <strong>UIGetScreenImage(</strong>), it&#8217;s good practice to define the method somewhere within our code. This will keep the compiler from generating the warning: implicit declaration of function &#8216;UIGetScreenImage.&#8217; The next steps involve capturing the screen and creating a UIImage object.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Define at top of implementation file</span>
CGImageRef UIGetScreenImage<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>;
&nbsp;
...
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>button
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Capture screen here...</span>
  CGImageRef screen <span style="color: #002200;">=</span> UIGetScreenImage<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
  UIImage<span style="color: #002200;">*</span> image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>screen<span style="color: #002200;">&#93;</span>;
  CGImageRelease<span style="color: #002200;">&#40;</span>screen<span style="color: #002200;">&#41;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Save the captured image to photo album</span>
  UIImageWriteToSavedPhotosAlbum<span style="color: #002200;">&#40;</span>image, self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>image<span style="color: #002200;">:</span>didFinishSavingWithError<span style="color: #002200;">:</span>contextInfo<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>Saving Captured Image to Photo Album</h5>
<p>If you look at the last line of code above, this will initiate a request to write the image to the Photo Album. The code below shows the method that is called once the save is completed, in this example I display a message indicating success or failure.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>image<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIImage <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>image didFinishSavingWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error contextInfo<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>contextInfo
<span style="color: #002200;">&#123;</span>
  UIAlertView <span style="color: #002200;">*</span>alert;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Unable to save the image  </span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>error<span style="color: #002200;">&#41;</span>
    alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error&quot;</span> 
                            message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Unable to save image to Photo Album.&quot;</span> 
                            delegate<span style="color: #002200;">:</span>self cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ok&quot;</span> 
                            otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #a61390;">else</span> <span style="color: #11740a; font-style: italic;">// All is well</span>
    alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Success&quot;</span> 
                            message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Image saved to Photo Album.&quot;</span> 
                            delegate<span style="color: #002200;">:</span>self cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ok&quot;</span> 
                            otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>Simulator Support</h5>
<p>From what I can tell, <strong>UIGetScreenImage()</strong> is not supported on the simulator, you&#8217;ll need to load the app on a device to see how this works.</p>
<h5>UIGetScreenImage Source Code Example</h5>
<p>Here is a link to <a href="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/05/getScreenImage.zip">download the Xcode project for UIGetScreenImage Source</a>.</p>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><!-- Do not remove -->]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/user-interface/screen-capture-using-uigetscreenimage.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

