<?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>Cayden Liew</title>
	<atom:link href="http://caydenliew.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://caydenliew.com</link>
	<description>When you think it&#039;s impossible, think again...</description>
	<lastBuildDate>Fri, 18 May 2012 15:07:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Connect IOS App to ASMX Webservice in MAC</title>
		<link>http://caydenliew.com/2012/05/connect-ios-app-to-asmx-webservice-in-mac/</link>
		<comments>http://caydenliew.com/2012/05/connect-ios-app-to-asmx-webservice-in-mac/#comments</comments>
		<pubDate>Fri, 18 May 2012 14:51:26 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[asmx]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[port forward]]></category>
		<category><![CDATA[virtualbox]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=248</guid>
		<description><![CDATA[Just for sharing, i was working on a project that needs the iphone app to be connected to an asmx webservice. ASMX runs in windows, under .NET architecture. Of course, the best fix is to get a Windows machine. As a MAC user without a Windows PC, I have to figure out how to run a .NET webservice in my MAC so that i can test my iphone app&#8217;s webservice with my MACBOOK. Generally, there [...]]]></description>
			<content:encoded><![CDATA[<p>Just for sharing, i was working on a project that needs the iphone app to be connected to an asmx webservice. ASMX runs in windows, under .NET architecture. Of course, the best fix is to get a Windows machine. As a MAC user without a Windows PC, I have to figure out how to run a .NET webservice in my MAC so that i can test my iphone app&#8217;s webservice with my MACBOOK.</p>
<p>Generally, there are 6 steps to make it possible:</p>
<ul>
<li>1. Install a virtual machine.</li>
<li>2. Install Windows in the virtual machine.</li>
<li>3. Setup the webservice in the virtual machine.</li>
<li>4. Port forward from the guest machine to host machine under NAT network.</li>
<li>5. Get your MAC&#8217;s ip address.</li>
<li>6. Connect iphone app to your MAC&#8217;s ip with the port.</li>
</ul>
<h2>Step 1 to 3: Installation and Setup</h2>
<p>
I won&#8217;t be explaining how to setup a virtual machine or install a Windows here. What i&#8217;ve done was installing <a href="https://www.virtualbox.org/wiki/Downloads" target="_blank">VirtualBox</a>, and <a href="http://www.google.com.sg/url?sa=t&#038;rct=j&#038;q=&#038;esrc=s&#038;source=web&#038;cd=2&#038;ved=0CG8QFjAB&#038;url=http%3A%2F%2Fwindows.microsoft.com%2Fen-US%2Fwindows-8%2Fiso&#038;ei=ft-1T_ysApHSrQfAm_H3Bw&#038;usg=AFQjCNHtKjtkYuo-x8YtA60P8HtSDEBi0Q&#038;sig2=AoMXDlPQsBn96vGjh6vQ1g" target="_blank" >Windows 8 Consumer Preview</a> since they are free. After setting up Windows, you can just follow some guide to setup IIS and run your webservice.
</p>
<h2>Step 4: Port Forwarding</h2>
<p>
One nice feature in VirtualBox 4 is that the port forwarding is really simple to configure. In your virtualBox network setting, choose NAT as the Netword Adaptor like the screen below:
</p>
<p>
<a href="http://caydenliew.com/wp-content/uploads/2012/05/nat.png"><img src="http://caydenliew.com/wp-content/uploads/2012/05/nat-300x246.png" alt="NAT" title="nat" width="300" height="246" class="alignleft size-medium wp-image-252" /></a>
</p>
<p>Then check your guest machine ip address, we need the ip to do the port forward. For my case, the ip address is 10.0.2.15</p>
<p>Now, go back to the network setting, click &#8216;Port forwarding&#8217; button, and fill up your ip address and port like screen below. The Guest IP is the guest machine IP address you get from the Windows. The Host port is the port in you host machine(MAC) which you&#8217;ll map to. The Guest Port is the guest machine port which is 80 for HTTP.
</p>
<p>
<a href="http://caydenliew.com/wp-content/uploads/2012/05/port_forward.png"><img src="http://caydenliew.com/wp-content/uploads/2012/05/port_forward-300x211.png" alt="port forward" title="port_forward" width="300" height="211" class="alignleft size-medium wp-image-253" /></a>
</p>
<p>So, now if you can run your webservice in your guest machine, for example http:localhost/mywebservice, you should be able to see the webservice in your host machine with url http://localhost:8888/mywebservice. This is because you have forward the port 80 from guest to host&#8217;s port 8888.</p>
<h2>Step 5: Get your Mac IP Address</h2>
<p>After you are able to access the guest machine&#8217;s webservice in your host machine, now you can try to access it from your iphone. Before run the app form your iphone, just do a quick check. Get your MAC&#8217;s ip address, type in the ip and webservice url in your iphone&#8217;s safari browser like: http://MAC_IP_ADDRESS:8888/webservice. If you see the webservice running in your safari, you are almost there.</p>
<p>Before you proceed, one more important step is to check your webservice&#8217;s Web.config file. In order to access the webservice remotely, you need to insert:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webServices<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;protocols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpSoap12&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpSoap&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpGet&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpPost&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/protocols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webServices<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></div></div>

<p>Without this, you will not be able to remotely access the webservice from your iphone app.</p>
<h2>Step 6: Run you app!</h2>
<p>Now, run your iphone app that connect to the webservice!</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/05/connect-ios-app-to-asmx-webservice-in-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KLii &#8211; Discover Something Special</title>
		<link>http://caydenliew.com/2012/05/klii-discover-something-special/</link>
		<comments>http://caydenliew.com/2012/05/klii-discover-something-special/#comments</comments>
		<pubDate>Fri, 18 May 2012 07:11:58 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[coupon]]></category>
		<category><![CDATA[deals]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[KLii]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=256</guid>
		<description><![CDATA[Check out the latest iPhone app by Ticket-Inn &#8211; KLii KLii is not just another app that suggest deals, it learns as you use it. And it suggests what you like/dislike, and what&#8217;s nearby. With KLii, you can discover YOUR best deal in town! http://klii.sg]]></description>
			<content:encoded><![CDATA[<p><a href="http://caydenliew.com/wp-content/uploads/2012/05/KLii-App-Icon-512px-X-512px.png"><img src="http://caydenliew.com/wp-content/uploads/2012/05/KLii-App-Icon-512px-X-512px-300x300.png" alt="KLii" title="KLii-App-Icon-(512px-X-512px)" width="300" height="300" class="alignleft size-medium wp-image-258" /></a></p>
<p>Check out the latest iPhone app by Ticket-Inn &#8211; <a href=" http://itunes.apple.com/us/app/klii/id523567189?mt=8" title="KLii" target="_blank">KLii</a></p>
<p>KLii is not just another app that suggest deals, it learns as you use it. And it suggests what you like/dislike, and what&#8217;s nearby.</p>
<p>
<a href="http://caydenliew.com/wp-content/uploads/2012/05/1.Menu-Page.png"><img src="http://caydenliew.com/wp-content/uploads/2012/05/1.Menu-Page-200x300.png" alt="" title="1.Menu-Page" width="200" height="300" class="alignleft size-medium wp-image-262" /></a><a href="http://caydenliew.com/wp-content/uploads/2012/05/4.Exclusive-Page.png"><img src="http://caydenliew.com/wp-content/uploads/2012/05/4.Exclusive-Page-200x300.png" alt="" title="4.Exclusive-Page" width="200" height="300" class="alignleft size-medium wp-image-263" /></a></p>
<p>With KLii, you can discover <strong>YOUR</strong> best deal in town!</p>
<p><a href="http://klii.sg" title="KLii" target="_blank">http://klii.sg</a></p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/05/klii-discover-something-special/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CLTickerView &#8211; An IOS Ticker</title>
		<link>http://caydenliew.com/2012/03/cltickerview-an-ios-ticker/</link>
		<comments>http://caydenliew.com/2012/03/cltickerview-an-ios-ticker/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 14:29:47 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[IOS]]></category>
		<category><![CDATA[IOS Library]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[CLTickerView]]></category>
		<category><![CDATA[ios control]]></category>
		<category><![CDATA[ios library]]></category>
		<category><![CDATA[ios ticker]]></category>
		<category><![CDATA[iphone ticker]]></category>
		<category><![CDATA[marquee]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=237</guid>
		<description><![CDATA[CLTickerView is an IOS library for building a ticker or marquee in HTML. It is built with UIScrollView, UILabel and NSTimer. Features: Animated text from right to left, like HTML Marquee Tap on text to stop, drag to scroll, and release to resume the animation This is how you can use the library: CLTickerView *ticker = &#91;&#91;CLTickerView alloc&#93; initWithFrame:CGRectMake&#40;0, 20, 320, 30&#41;&#93;; //set the text ticker.marqueeStr = @&#34;This is a sample ios marquee using scrollview [...]]]></description>
			<content:encoded><![CDATA[<p>CLTickerView is an IOS library for building a ticker or marquee in HTML. It is built with UIScrollView, UILabel and NSTimer. </p>
<p><a href="http://caydenliew.com/wp-content/uploads/2012/03/CLTickerView.png"><img src="http://caydenliew.com/wp-content/uploads/2012/03/CLTickerView-300x150.png" alt="ios ticker" title="CLTickerView" width="300" height="150" class="alignleft size-medium wp-image-242" /></a></p>
<p><b>Features:</b></p>
<ul>
<li>Animated text from right to left, like HTML Marquee</li>
<li>Tap on text to stop, drag to scroll, and release to resume the animation</li>
</ul>
<p>This is how you can use the library:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">CLTickerView <span style="color: #339933;">*</span>ticker <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>CLTickerView alloc<span style="color: #009900;">&#93;</span> initWithFrame<span style="color: #339933;">:</span>CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">20</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//set the text</span>
ticker.<span style="color: #202020;">marqueeStr</span> <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;This is a sample ios marquee using scrollview and timer. You can also manually control it by scrolling left 
                      or right, or touch on it to stop it, and release it to auto restart the marquee.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//set the font</span>
ticker.<span style="color: #202020;">marqueeFont</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #339933;">:</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">view</span> addSubview<span style="color: #339933;">:</span>ticker<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>ticker release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p><b>Demo</b><br />
<iframe width="420" height="315" src="http://www.youtube.com/embed/moI3ROPBm4Y" frameborder="0" allowfullscreen></iframe>
</p>
<p>The library with demo is available on my <a href="https://github.com/caydenliew/CLTickerView" target="_blank">Github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/03/cltickerview-an-ios-ticker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customize UISearchBar Background Image</title>
		<link>http://caydenliew.com/2012/01/customize-uisearchbar-background-image/</link>
		<comments>http://caydenliew.com/2012/01/customize-uisearchbar-background-image/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 11:50:47 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[Customize UISearchBar]]></category>
		<category><![CDATA[UISearchBar]]></category>
		<category><![CDATA[UISearchBar background image]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=231</guid>
		<description><![CDATA[In this post, I&#8217;ll walkthrough how to customize the background of UISearchBar. In order to customize the UISearchBar, first we need to know it&#8217;s subviews. We can get the subviews by running the code below: for &#40;UIView *subview in &#91;searchBar subviews&#93;&#41; &#123; NSLog&#40;@&#34;%@&#34;, &#91;subview class&#93;&#41;; &#125; If you run the code above, and you are running IOS 4.3 and above, you should see two subviews &#8220;UISearchBarBackground&#8221; and &#8220;UISearchBarTextField&#8221;. So, we know that UISearchBar consist of [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I&#8217;ll walkthrough how to customize the background of UISearchBar.</p>
<p>In order to customize the UISearchBar, first we need to know it&#8217;s subviews. We can get the subviews by running the code below:
</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>UIView <span style="color: #339933;">*</span>subview in <span style="color: #009900;">&#91;</span>searchBar subviews<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;%@&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>subview class<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you run the code above, and you are running IOS 4.3 and above, you should see two subviews &#8220;UISearchBarBackground&#8221; and &#8220;UISearchBarTextField&#8221;. So, we know that UISearchBar consist of a background view and a textfield, that make sense.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2012/01/default-uisearchbar.png"><img src="http://caydenliew.com/wp-content/uploads/2012/01/default-uisearchbar-300x27.png" alt="default-uisearchbar" title="default-uisearchbar" width="300" height="27" class="alignleft size-medium wp-image-232" /></a></p>
<p>The default UISearchBar looks like the screenshot above, so let&#8217;s try to remove the background and see how the UISearchBar will look like by running the code below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>UIView <span style="color: #339933;">*</span>subview in <span style="color: #009900;">&#91;</span>searchBar subviews<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>subview isKindOfClass<span style="color: #339933;">:</span>NSClassFromString<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;UISearchBarBackground&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#91;</span>subview removeFromSuperview<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code is quite straight forward, it loop through all the subviews of UISearchBar and check if any subview belongs to the class &#8220;UISearchBarBackground&#8221;, if it is, remove it.</p>
<p>After you run the code, you should be able to see something like screenshot below. The background has been removed.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2012/01/uisearchbar-without-background.png"><img src="http://caydenliew.com/wp-content/uploads/2012/01/uisearchbar-without-background-300x26.png" alt="uisearchbar-without-background" title="uisearchbar-without-background" width="300" height="26" class="alignleft size-medium wp-image-233" /></a></p>
<p>Now we only left with the UITextfield, we can customize the UITexfield by running the code below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>UIView <span style="color: #339933;">*</span>subview in <span style="color: #009900;">&#91;</span>searchBar subviews<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>subview isKindOfClass<span style="color: #339933;">:</span>NSClassFromString<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;UISearchBarBackground&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #009900;">&#91;</span>subview removeFromSuperview<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>subview isKindOfClass<span style="color: #339933;">:</span>NSClassFromString<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;UISearchBarTextField&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>UITextField <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>subview setBackground<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;searchboxbg.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code above look for the UISearchBarTextField subview and set it&#8217;s background with our own image &#8220;searchboxbg.png&#8221;.</p>
<p>After running the code, you&#8217;ll see something like screenshot below.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2012/01/custom-uisearchbar.png"><img src="http://caydenliew.com/wp-content/uploads/2012/01/custom-uisearchbar-300x28.png" alt="custom-uisearchbar" title="custom-uisearchbar" width="300" height="28" class="alignleft size-medium wp-image-234" /></a></p>
<p>This is how you can customize the UISearchBar.</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/01/customize-uisearchbar-background-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>O level POA iPhone App</title>
		<link>http://caydenliew.com/2012/01/o-level-poa-iphone-app/</link>
		<comments>http://caydenliew.com/2012/01/o-level-poa-iphone-app/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 04:26:40 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[O Level]]></category>
		<category><![CDATA[POA]]></category>
		<category><![CDATA[Principles of Accounts]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=215</guid>
		<description><![CDATA[New iPhone app released on Chinese New Year, Jan 25, 2012. App name: O Level POA Description: Learn GCE &#8216;N&#8217; and &#8216;O&#8217; Level Principles of Accounts by reviewing the notes specially designed for Secondary 3, 4 and 5 students in Singapore. You will be able to read full notes of all topics and test yourself by attempting on at least 10 multiple-choiced questions per topic. Correct answers will be marked in green while wrong answers [...]]]></description>
			<content:encoded><![CDATA[<p style="margin:5px 0 5px 0"><a href="http://caydenliew.com/wp-content/uploads/2012/01/s1.jpg"><img src="http://caydenliew.com/wp-content/uploads/2012/01/s1-200x300.jpg" alt="" title="POA-1" width="200" height="300" class="alignleft size-medium wp-image-217" /></a></p>
<p>New iPhone app released on Chinese New Year, Jan 25, 2012.</p>
<p><b>App name: <a href="http://itunes.apple.com/us/app/o-level-poa/id494556980?ls=1&#038;mt=8" title="O Level POA" target="_blank">O Level POA</a></b></p>
<p><b>Description:</b></p>
<p>Learn GCE &#8216;N&#8217; and &#8216;O&#8217; Level Principles of Accounts by reviewing the notes specially designed for Secondary 3, 4 and 5 students in Singapore. </p>
<p>You will be able to read full notes of all topics and test yourself by attempting on at least 10 multiple-choiced questions per topic. </p>
<p>Correct answers will be marked in green while wrong answers will be highlighted in red. Users can also submit questions via the app to the author for clarifications. The author is a current school teacher from the Ministry of Education.</p>
<p style="margin:10px 0 10px 0">
<a href="http://caydenliew.com/wp-content/uploads/2012/01/s2.jpg"><img src="http://caydenliew.com/wp-content/uploads/2012/01/s2-200x300.jpg" alt="" title="POA-2" width="200" height="300" class="alignright size-medium wp-image-218" /></a>
</p>
<p style="margin:10px 0 10px 0">
<a href="http://caydenliew.com/wp-content/uploads/2012/01/s5.jpg"><img src="http://caydenliew.com/wp-content/uploads/2012/01/s5-200x300.jpg" alt="" title="POA-3" width="200" height="300" class="alignleft size-medium wp-image-219" /></a></p>
<p style="margin:10px 0 10px 0"><a href="http://caydenliew.com/wp-content/uploads/2012/01/s4.jpg"><img src="http://caydenliew.com/wp-content/uploads/2012/01/s4-200x300.jpg" alt="" title="POA-4" width="200" height="300" class="alignleft size-medium wp-image-222" /></a></p>
<p>You can download the app <a href="http://itunes.apple.com/us/app/o-level-poa/id494556980?ls=1&#038;mt=8" title="O Level POA" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/01/o-level-poa-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UILabel With Different Style Text</title>
		<link>http://caydenliew.com/2012/01/uilabel-with-different-style-text/</link>
		<comments>http://caydenliew.com/2012/01/uilabel-with-different-style-text/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 02:27:14 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[IOS Library]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[IOS font style]]></category>
		<category><![CDATA[ios tutorial]]></category>
		<category><![CDATA[iPhone tutorial]]></category>
		<category><![CDATA[NSAttributedStrings]]></category>
		<category><![CDATA[OHAttributedStrings]]></category>
		<category><![CDATA[UILabel]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=204</guid>
		<description><![CDATA[There are situations when we need to style a UILabel differently for each text. This can be done by using NSAttributedStrings. Thanks to the library OHAttributedLabel, you can achieve the styled NSAttributedStrings easily under one UILabel. In order to use the library, you must first import the CoreText Framework. In the example below, I style the label so that the text are splited into 2 different colors. OHAttributedLabel *label; NSString *txt = @&#34;page (1 of [...]]]></description>
			<content:encoded><![CDATA[<p>There are situations when we need to style a UILabel differently for each text. This can be done by using NSAttributedStrings.
</p>
<p>
Thanks to the library <a href="https://github.com/AliSoftware/OHAttributedLabel#readme" title="OHAttributedLabel" target="_blank">OHAttributedLabel</a>, you can achieve the styled NSAttributedStrings easily under one UILabel.
</p>
<p>
In order to use the library, you must first import the CoreText Framework. In the example below, I style the label so that the text are splited into 2 different colors.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">    OHAttributedLabel <span style="color: #339933;">*</span>label<span style="color: #339933;">;</span>
    NSString <span style="color: #339933;">*</span>txt <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;page (1 of 10)&quot;</span><span style="color: #339933;">;</span>
    NSMutableAttributedString<span style="color: #339933;">*</span> attrStr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSMutableAttributedString attributedStringWithString<span style="color: #339933;">:</span>txt<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    NSArray <span style="color: #339933;">*</span>splits <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>txt componentsSeparatedByString<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;(&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#91;</span>attrStr setTextColor<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UIColor redColor<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#91;</span>attrStr setFont<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #339933;">:</span><span style="color: #0000dd;">18</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#91;</span>attrStr setTextAlignment<span style="color: #339933;">:</span>CTTextAlignmentFromUITextAlignment<span style="color: #009900;">&#40;</span>UITextAlignmentCenter<span style="color: #009900;">&#41;</span>     
                lineBreakMode<span style="color: #339933;">:</span>CTLineBreakModeFromUILineBreakMode<span style="color: #009900;">&#40;</span>UILineBreakModeTailTruncation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>splits count<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> start <span style="color: #339933;">=</span>  <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>splits objectAtIndex<span style="color: #339933;">:</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> length<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> end <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>splits objectAtIndex<span style="color: #339933;">:</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> length<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#91;</span>attrStr setTextColor<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UIColor blackColor<span style="color: #009900;">&#93;</span> range<span style="color: #339933;">:</span>NSMakeRange<span style="color: #009900;">&#40;</span>start<span style="color: #339933;">,</span> end<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    label.<span style="color: #202020;">attributedText</span> <span style="color: #339933;">=</span> attrStr<span style="color: #339933;">;</span></pre></div></div>

</p>
<p>The result will be like the screenshot below:<br />
<a href="http://caydenliew.com/wp-content/uploads/2012/01/ohattributedLabel.png"><img src="http://caydenliew.com/wp-content/uploads/2012/01/ohattributedLabel.png" alt="ohattributedLabel" title="ohattributedLabel" width="223" height="112" class="alignleft size-full wp-image-205" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2012/01/uilabel-with-different-style-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customizing UINavigationbar</title>
		<link>http://caydenliew.com/2011/12/customizing-uinavigationbar/</link>
		<comments>http://caydenliew.com/2011/12/customizing-uinavigationbar/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 13:11:30 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[custom navigation bar]]></category>
		<category><![CDATA[forBarMetrics]]></category>
		<category><![CDATA[setBackgroundImage]]></category>
		<category><![CDATA[UINavigationBar]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=198</guid>
		<description><![CDATA[Before IOS 5.0, UINavigationbar can be customized by using &#8216;Category&#8217;. On IOS 5.0 onwards, customizing with &#8216;category&#8217; doesn&#8217;t work anymore, instead we can use a new API called: - &#40;void&#41;setBackgroundImage:&#40;UIImage *&#41;backgroundImage forBarMetrics:&#40;UIBarMetrics&#41;barMetrics In order to customize UINavagationBar for both IOS 5.0 and below IOS 5.0 devices, we have to prepare these two methods: 1. Write a category for UINavigationBar (for IOS 4.3 and below) 2. Check if device is IOS 5.0 and above, use &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Before IOS 5.0, UINavigationbar can be customized by using &#8216;Category&#8217;. On IOS 5.0 onwards, customizing with &#8216;category&#8217; doesn&#8217;t work anymore, instead we can use a new API called:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>setBackgroundImage<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIImage <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>backgroundImage forBarMetrics<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIBarMetrics<span style="color: #009900;">&#41;</span>barMetrics</pre></div></div>

</p>
<p>
<a href="http://caydenliew.com/wp-content/uploads/2011/12/custom-uinavigationbar.png"><img src="http://caydenliew.com/wp-content/uploads/2011/12/custom-uinavigationbar-300x160.png" alt="custom-uinavigationbar" title="custom-uinavigationbar" width="300" height="160" class="alignleft size-medium wp-image-199" /></a>
</p>
<p>In order to customize UINavagationBar for both IOS 5.0 and below IOS 5.0 devices, we have to prepare these two methods:</p>
<ul>
<li>1. Write a category for UINavigationBar (for IOS 4.3 and below)</li>
<li>2. Check if device is IOS 5.0 and above, use &#8211; (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics</li>
</ul>
<p>To create a category, create a new file name &#8216;CustomNavigationBar&#8217;.<br />
In &#8216;CustomNavigationBar.h&#8217;,</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">@interface CustomNavigationBar <span style="color: #339933;">:</span> UINavigationBar
@end</pre></div></div>

<p>In &#8216;CustomNavigationBar.m&#8217;, draw the navigation bar with your custom image,</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &quot;CustomNavigationBar.h&quot;</span>
&nbsp;
@implementation UINavigationBar <span style="color: #009900;">&#40;</span>UINavigationBarCategory<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>drawRect<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>CGRect<span style="color: #009900;">&#41;</span>rect <span style="color: #009900;">&#123;</span>
    UIColor <span style="color: #339933;">*</span>color <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIColor darkGrayColor<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    UIImage <span style="color: #339933;">*</span>img  <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span> @<span style="color: #ff0000;">&quot;img-bgtopbar.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#91;</span>img drawInRect<span style="color: #339933;">:</span>CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> self.<span style="color: #202020;">frame</span>.<span style="color: #202020;">size</span>.<span style="color: #202020;">width</span><span style="color: #339933;">,</span> self.<span style="color: #202020;">frame</span>.<span style="color: #202020;">size</span>.<span style="color: #202020;">height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    self.<span style="color: #202020;">tintColor</span> <span style="color: #339933;">=</span> color<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
@end</pre></div></div>

</p>
<p>To replace the default Navigation bar, just #import &#8216;CustomNavigationBar.h&#8217; in any classes that need to be customized.</p>
<p>To determine the IOS version, check like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">float</span> deviceVersion <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UIDevice currentDevice<span style="color: #009900;">&#93;</span> systemVersion<span style="color: #009900;">&#93;</span> floatValue<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>deviceVersion <span style="color: #339933;">&gt;=</span> <span style="color:#800080;">5.0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">navigationController</span>.<span style="color: #202020;">navigationBar</span> setBackgroundImage<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;img-bgtopbar.png&quot;</span><span style="color: #009900;">&#93;</span> forBarMetrics<span style="color: #339933;">:</span>UIBarMetricsDefault<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p>The code above check if the device version is equal to or more than IOS 5.0, if so, use the &#8216;setBackgroundImage&#8217; API. With these 2 methods, you can customize the UINavigationBar for IOS 4.3 and below as well as IOS 5.0</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2011/12/customizing-uinavigationbar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Modify XCode 4.2 Project Template</title>
		<link>http://caydenliew.com/2011/12/modify-xcode-4-2-project-template/</link>
		<comments>http://caydenliew.com/2011/12/modify-xcode-4-2-project-template/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 13:55:25 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[core data option]]></category>
		<category><![CDATA[Tabbed Application.xctemplate]]></category>
		<category><![CDATA[templateinfo.plist]]></category>
		<category><![CDATA[xcode 4.2 template]]></category>
		<category><![CDATA[xctemplate]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=191</guid>
		<description><![CDATA[In this post I&#8217;ll show you how to modify the XCode 4.2 Project Template. When we create a new project in XCode, we can choose which project template to use. However, some project templates provide an options to use Core Data while some not. To enable the Core Data option in a project template, we need to modify the &#8216;TemplateInfo.plist&#8217; which you can find at: Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/&#40;Application Type&#41;.xctemplate/TemplateInfo.plist For example, by default my Tabbed Application [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll show you how to modify the XCode 4.2 Project Template.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2011/12/xcode-template.jpg"><img src="http://caydenliew.com/wp-content/uploads/2011/12/xcode-template-300x203.jpg" alt="xcode-template" title="xcode-template" width="300" height="203" class="alignleft size-medium wp-image-192" /></a></p>
<p>When we create a new project in XCode, we can choose which project template to use. However, some project templates provide an options to use Core Data while some not. To enable the Core Data option in a project template, we need to modify the &#8216;TemplateInfo.plist&#8217; which you can find at:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Developer<span style="color: #339933;">/</span>Platforms<span style="color: #339933;">/</span>iPhoneOS.<span style="color: #202020;">platform</span><span style="color: #339933;">/</span>Developer<span style="color: #339933;">/</span>Library<span style="color: #339933;">/</span>Xcode<span style="color: #339933;">/</span>Templates<span style="color: #339933;">/</span>Project Templates<span style="color: #339933;">/</span>Application<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>Application Type<span style="color: #009900;">&#41;</span>.<span style="color: #202020;">xctemplate</span><span style="color: #339933;">/</span>TemplateInfo.<span style="color: #202020;">plist</span></pre></div></div>

</p>
<p>For example, by default my Tabbed Application does not provide the core data option, what i can do is to open up the template for Tabbed Application at:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">/</span>DeveloperNew<span style="color: #339933;">/</span>Platforms<span style="color: #339933;">/</span>iPhoneOS.<span style="color: #202020;">platform</span><span style="color: #339933;">/</span>Developer<span style="color: #339933;">/</span>Library<span style="color: #339933;">/</span>Xcode<span style="color: #339933;">/</span>Templates<span style="color: #339933;">/</span>Project Templates<span style="color: #339933;">/</span>Application<span style="color: #339933;">/</span>Tabbed Application.<span style="color: #202020;">xctemplate</span><span style="color: #339933;">/</span>TemplateInfo.<span style="color: #202020;">plist</span></pre></div></div>

<p>Open the TemplateInfo.plist in XML format. Then just add one more line:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span>com.<span style="color: #202020;">apple</span>.<span style="color: #202020;">dt</span>.<span style="color: #202020;">unit</span>.<span style="color: #202020;">coreDataCocoaTouchApplication</span><span style="color: #339933;">&lt;/</span>string<span style="color: #339933;">&gt;</span></pre></div></div>

<p>under the &#8216;Ancestors&#8217; key like below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE plist PUBLIC <span style="color: #ff0000;">&quot;-//Apple//DTD PLIST 1.0//EN&quot;</span> <span style="color: #ff0000;">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>plist version<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>dict<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>key<span style="color: #339933;">&gt;</span>Ancestors<span style="color: #339933;">&lt;/</span>key<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>array<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span>com.<span style="color: #202020;">apple</span>.<span style="color: #202020;">dt</span>.<span style="color: #202020;">unit</span>.<span style="color: #202020;">storyboardApplication</span><span style="color: #339933;">&lt;/</span>string<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span>com.<span style="color: #202020;">apple</span>.<span style="color: #202020;">dt</span>.<span style="color: #202020;">unit</span>.<span style="color: #202020;">coreDataCocoaTouchApplication</span><span style="color: #339933;">&lt;/</span>string<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>array<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>key<span style="color: #339933;">&gt;</span>Concrete<span style="color: #339933;">&lt;/</span>key<span style="color: #339933;">&gt;</span>
  ...</pre></div></div>

</p>
<p>Now when you create a new Tabbed Application, you&#8217;ll see an option for Core Data.</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2011/12/modify-xcode-4-2-project-template/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>QRCode Reader With ZXing Library</title>
		<link>http://caydenliew.com/2011/12/qrcode-reader-with-zxing-library/</link>
		<comments>http://caydenliew.com/2011/12/qrcode-reader-with-zxing-library/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 10:43:58 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iPhone tutorial]]></category>
		<category><![CDATA[QRCode]]></category>
		<category><![CDATA[ZXing]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=181</guid>
		<description><![CDATA[ZXing is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. In this tutorial, Im going to show you how to make a small modification to the library so that the QRCode reader can read from image as well instead of just camera. First of all, download the ZXing-1.7.zip. After you unzipped it, look for the folder &#8216;iphone&#8217; -> &#8216;Barcodes&#8217;, this is the sample project we will be [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/zxing/" title="ZXing" target="_blank">ZXing</a> is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. In this tutorial, Im going to show you how to make a small modification to the library so that the QRCode reader can read from image as well instead of just camera.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2011/12/Test.png"><img src="http://caydenliew.com/wp-content/uploads/2011/12/Test.png" alt="QRCode" title="QRCode" width="33" height="33" class="alignleft size-full wp-image-184" /></a>
</p>
<p>First of all, download the <a href="http://code.google.com/p/zxing/downloads/detail?name=ZXing-1.7.zip&#038;can=2&#038;q=" title="ZXing" target="_blank">ZXing-1.7.zip</a>. After you unzipped it, look for the folder &#8216;iphone&#8217; -> &#8216;Barcodes&#8217;, this is the sample project we will be using in this tutorial. If you launch the app in simulator and do the code scanning, it won&#8217;t work as it requires a camera which a simulator doesn&#8217;t have. In order to test the QRCode reader without a device, here&#8217;s a little modification to the library so that it can either scan from camera or image.</p>
<p>In the Barcodes project, you&#8217;ll see a &#8216;ZXMainViewController.mm&#8217;, this is the main controller of the project. There&#8217;s a function called:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>scan<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>sender</pre></div></div>

<p>which is the event for scanning button.</p>
<p>What we are going to modify is the controller that control the QRCode scanning:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">ZXingWidgetController <span style="color: #339933;">*</span>widController</pre></div></div>

<p>We will tell this widController to scan from an image instead of using camera. To do that, we need to add 2 extra properties to the ZXingWidgetController.</p>
<p>Now, in the project directory, look for &#8216;dependencies&#8217;. There&#8217;s a &#8216;ZXingWidget.Xcodeproj&#8217;, look for &#8216;classes&#8217; directory, we are only interested in 2 files which are &#8216;ZXingWidgetController.h&#8217; and &#8216;ZXingWidgetController.m&#8217;.</p>
<p>In &#8216;ZXingWidgetController.h&#8217;, add the 2 properties like below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">@property <span style="color: #009900;">&#40;</span>nonatomic<span style="color: #339933;">,</span> assign<span style="color: #009900;">&#41;</span> BOOL isCamera<span style="color: #339933;">;</span>
@property <span style="color: #009900;">&#40;</span>nonatomic<span style="color: #339933;">,</span> retain<span style="color: #009900;">&#41;</span> UIImage <span style="color: #339933;">*</span>scanImage<span style="color: #339933;">;</span></pre></div></div>

<p>The property &#8216;isCamera&#8217; is to tell the controller to either scan from camera or image. The property &#8216;scanImage&#8217; is the image to be scanned, which is a QRCode. </p>
<p>In &#8216;ZXingWidgetController.m&#8217;, syntesize the properties like:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">@synthesize isCamera<span style="color: #339933;">,</span> scanImage<span style="color: #339933;">;</span></pre></div></div>

<p>In the &#8216;dealloc&#8217; function, release the &#8216;scanImage&#8217; we retain:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>scanImage release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p>Now, create a new function in &#8216;ZXingWidgetController.m&#8217; to scan the image:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>scannedWithImage<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIImage <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>img size<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>CGRect<span style="color: #009900;">&#41;</span>rect<span style="color: #009900;">&#123;</span>
    Decoder <span style="color: #339933;">*</span>d <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>Decoder alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    d.<span style="color: #202020;">readers</span> <span style="color: #339933;">=</span> readers<span style="color: #339933;">;</span>
    d.<span style="color: #202020;">delegate</span> <span style="color: #339933;">=</span> self<span style="color: #339933;">;</span>
    decoding <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>d decodeImage<span style="color: #339933;">:</span>img cropRect<span style="color: #339933;">:</span>rect<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> YES <span style="color: #339933;">?</span> NO <span style="color: #339933;">:</span> YES<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#91;</span>d release<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, in &#8216;- (void)viewDidAppear:(BOOL)animated&#8217;, modify the code like below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>viewDidAppear<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>BOOL<span style="color: #009900;">&#41;</span>animated <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#91;</span>super viewDidAppear<span style="color: #339933;">:</span>animated<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  self.<span style="color: #202020;">isStatusBarHidden</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UIApplication sharedApplication<span style="color: #009900;">&#93;</span> isStatusBarHidden<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isStatusBarHidden<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>UIApplication sharedApplication<span style="color: #009900;">&#93;</span> setStatusBarHidden<span style="color: #339933;">:</span>YES<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  decoding <span style="color: #339933;">=</span> YES<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isCamera<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#91;</span>self initCapture<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#91;</span>self.<span style="color: #202020;">view</span> addSubview<span style="color: #339933;">:</span>overlayView<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#91;</span>overlayView setPoints<span style="color: #339933;">:</span>nil<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#91;</span>self scannedWithImage<span style="color: #339933;">:</span>self.<span style="color: #202020;">scanImage</span> size<span style="color: #339933;">:</span>CGRectMake<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> self.<span style="color: #202020;">scanImage</span>.<span style="color: #202020;">size</span>.<span style="color: #202020;">width</span><span style="color: #339933;">,</span> self.<span style="color: #202020;">scanImage</span>.<span style="color: #202020;">size</span>.<span style="color: #202020;">height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  wasCancelled <span style="color: #339933;">=</span> NO<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What it does here is to check whether it should scan from camera or image, if we choose to scan from image it will call the function &#8216;- (void)scannedWithImage:(UIImage *)img size:(CGRect)rect&#8217; we&#8217;ve just created.
</p>
<p>We can now go back to the &#8216;ZXMainViewController.m&#8217; to set the property of &#8216;ZXingWidgetController&#8217;.</p>
<p>In &#8216;- (IBAction)scan:(id)sender&#8217;, set the property like below:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  ZXingWidgetController <span style="color: #339933;">*</span>widController <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>ZXingWidgetController alloc<span style="color: #009900;">&#93;</span> initWithDelegate<span style="color: #339933;">:</span>self 
                                                                              showCancel<span style="color: #339933;">:</span>YES 
                                                                                OneDMode<span style="color: #339933;">:</span>NO<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  widController.<span style="color: #202020;">isCamera</span> <span style="color: #339933;">=</span> NO<span style="color: #339933;">;</span>
  UIImage <span style="color: #339933;">*</span>image <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>UIImage imageNamed<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;Test.png&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  widController.<span style="color: #202020;">scanImage</span> <span style="color: #339933;">=</span> image<span style="color: #339933;">;</span></pre></div></div>

<p>Here we set the &#8216;isCamera&#8217; to &#8216;No&#8217; so that we can scan from image. Then we set the QRCode image which is the &#8216;Test.png&#8217; to be scanned.</p>
<p>Now when you launch the app and press the scan button, it will scan from the QRCode image instead of camera.</p>
<p>You may download the sample code for this tutorial <a href="http://caydenliew.com/source-code/?did=3" title="QRCode reader" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2011/12/qrcode-reader-with-zxing-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing XML in Objective-C with TouchXML</title>
		<link>http://caydenliew.com/2011/12/parsing-xml-in-objective-c-with-touchxml/</link>
		<comments>http://caydenliew.com/2011/12/parsing-xml-in-objective-c-with-touchxml/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 09:38:40 +0000</pubDate>
		<dc:creator>cayden</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[IOS Library]]></category>
		<category><![CDATA[iPhone Tutorial]]></category>
		<category><![CDATA[objective-c xml]]></category>
		<category><![CDATA[parse xml]]></category>
		<category><![CDATA[TouchXML]]></category>
		<category><![CDATA[xml parser]]></category>

		<guid isPermaLink="false">http://caydenliew.com/?p=173</guid>
		<description><![CDATA[There&#8217;s a lot of libraries available for parsing XML in Objective-C, one of them is TouchXML. Here&#8217;s a sample source code on how to use TouchXML to parse XML data. You can get the TouchXML here. TouchXML is using XPath, if you never heard of XPath, read it more here.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot of libraries available for parsing XML in Objective-C, one of them is TouchXML.<br />
Here&#8217;s a <a href="http://caydenliew.com/source-code/?did=1">sample source code</a> on how to use TouchXML to parse XML data.</p>
<p><a href="http://caydenliew.com/wp-content/uploads/2011/12/xml_file.png"><img src="http://caydenliew.com/wp-content/uploads/2011/12/xml_file.png" alt="xml_file" title="xml_file" width="128" height="128" class="alignleft size-full wp-image-179" /></a></p>
<p>You can get the TouchXML <a href="https://github.com/TouchCode/TouchXML">here.</a></p>
<p>TouchXML is using XPath, if you never heard of XPath, read it more <a hre="http://www.w3schools.com/xpath/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://caydenliew.com/2011/12/parsing-xml-in-objective-c-with-touchxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

