<?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>A Tasty Pixel » Blog &#187; Development</title>
	<atom:link href="http://atastypixel.com/blog/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://atastypixel.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 16 May 2012 11:07:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>An Xcode 4 template to create universal static libraries</title>
		<link>http://atastypixel.com/blog/an-xcode-4-template-to-create-universal-static-libraries/</link>
		<comments>http://atastypixel.com/blog/an-xcode-4-template-to-create-universal-static-libraries/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 16:00:02 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Static Libraries]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=2497</guid>
		<description><![CDATA[I&#8217;ve created an Xcode 4 project template to create universal (armv6, armv7 and simulator) static libraries for iOS, based on Adam Martin&#8217;s script: iOS-Universal-Library-Template The existing static library template provided with Xcode only builds one architecture, which is not particularly suitable for distribution. A number of people have created scripts to create universal libraries, which [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created an Xcode 4 project template to create universal (armv6, armv7 and simulator) static libraries for iOS, based on <a href="http://red-glasses.com/index.php/tutorials/xcode4-make-a-library-in-one-file-that-works-on-both-device-and-simulator/comment-page-1/#comment-2226">Adam Martin&#8217;s script</a>:</p>

<p><a href="https://github.com/michaeltyson/iOS-Universal-Library-Template">iOS-Universal-Library-Template</a></p>

<p>The existing static library template provided with Xcode only builds one architecture, which is not particularly suitable for distribution. A number of people have created scripts to create universal libraries, which require some mucking around with Xcode target settings to use.</p>

<p>This template draws on this work to provide all that is required to produce universal libraries &#8211; just select the &#8216;Universal Static Library&#8217; type in the New Project/New Target dialog, and you&#8217;re all set.</p>

<p><img style="display:block; margin-left:auto; margin-right:auto;" class="aligncenter" src="http://atastypixel.com/blog/wp-content/uploads/2012/03/universal-static-library.jpg" alt="Universal static library" title="universal-static-library.jpg" border="0" width="450" height="305" /></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2497" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/an-xcode-4-template-to-create-universal-static-libraries/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Amazing Audio Engine: Funky Remote IO-based Core Audio Engine Coming Soon</title>
		<link>http://atastypixel.com/blog/the-amazing-audio-engine-funky-remote-io-based-core-audio-engine-coming-soon/</link>
		<comments>http://atastypixel.com/blog/the-amazing-audio-engine-funky-remote-io-based-core-audio-engine-coming-soon/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 22:14:38 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=2486</guid>
		<description><![CDATA[Huzzah! I&#8217;m announcing a new project which will be launching over the next couple of months. It&#8217;s called The Amazing Audio Engine, and it represents the product of years of experience with iOS audio. It&#8217;s a sophisticated iOS audio engine that lets developers skip the Core Audio learning curve, and get on with writing great [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://theamazingaudioengine.com"><img src="http://atastypixel.com/blog/wp-content/uploads/2012/03/amazingaudioengine.jpg" alt="The Amazing Audio Engine" title="amazingaudioengine.jpg" border="0" width="400" height="266" style="float:right; margin-left: 10px; margin-bottom: 10px;" class="alignright" /></a>Huzzah! I&#8217;m announcing a new project which will be launching over the next couple of months.</p>

<p>It&#8217;s called <a href="http://theamazingaudioengine.com">The Amazing Audio Engine</a>, and it represents the product of years of experience with iOS audio. It&#8217;s a sophisticated iOS audio engine that lets developers skip the Core Audio learning curve, and get on with writing great software.</p>

<p>The tech behind this is what drives <a href="http://loopyapp.com">Loopy and Loopy HD</a>, as well as the in-development <a href="http://audiob.us">Audiobus</a> app.</p>

<p><a href="http://theamazingaudioengine.com">Subscribe at theamazingaudioengine.com</a> to be kept in the loop as it approaches launch time.</p>

<p>Some of the features:</p>

<ul>
<li>Automatic mixing of multiple audio signals with per-channel volume and pan controls.</li>
<li>Built-in support for audio filtering and effects, including the ability to form complex filter chains, constructing channel groups, or even whole trees of groups, and filtering them as one composite signal.</li>
<li>Built-in support for audio input, including optional use of the Voice Processing IO unit, for automatic echo removal &#8211; great for VoIP.</li>
<li>Record or monitor the output of the whole audio system, for in-app session recording, or get the output of one channel, or any group of channels in the processing tree.</li>
<li>Support for any audio format (AudioStreamBasicDescription) that the hardware supports: Interleaved, non-interleaved, mono, stereo, 44.1kHz or any other supported sample rate, 16-bit, 8.24 fixed floating-point &#8211; whatever you need for your project.</li>
<li>Very light, efficient engine, designed from the ground up for speed. All Core Audio code is pure C; no Objective-   C or BSD calls, no locks, no memory allocation.</li>
<li>Efficient mixing of input signals, using Apple&#8217;s MultiChannelMixer.</li>
<li>Fast, lock-free synchronisation mechanism, enabling developers to send messages to the main thread from the Core Audio context, and vice versa, without
        locking or memory allocation from the Core Audio thread.  Message sending from the main thread is two-way, and can be asynchronous, with a response
        block, or synchronous.</li>
</ul>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2486" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/the-amazing-audio-engine-funky-remote-io-based-core-audio-engine-coming-soon/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Talking about Audiobus on a bicycle</title>
		<link>http://atastypixel.com/blog/talking-about-audiobus-on-a-bicycle/</link>
		<comments>http://atastypixel.com/blog/talking-about-audiobus-on-a-bicycle/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 16:00:37 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Audiobus]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=2472</guid>
		<description><![CDATA[Lets have a chat about Audiobus, you and I. Here, you can sit on the handlebars.]]></description>
			<content:encoded><![CDATA[<p>Lets have a chat about Audiobus, you and I. Here, you can sit on the handlebars.</p>

<iframe width="560" height="315" src="http://www.youtube.com/embed/Ktp4A4z70Q4" frameborder="0" allowfullscreen></iframe>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2472" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/talking-about-audiobus-on-a-bicycle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Audiobus action on Tumblr</title>
		<link>http://atastypixel.com/blog/audiobus-action-on-tumblr/</link>
		<comments>http://atastypixel.com/blog/audiobus-action-on-tumblr/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 12:55:14 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Audiobus]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=2468</guid>
		<description><![CDATA[I&#8217;m blogging about Audiobus&#8217;s development and other bits and pieces over on the Audiobus Tumblr blog. If you&#8217;re interested to see what I&#8217;m up to, do join me over there.]]></description>
			<content:encoded><![CDATA[<p><img src="http://atastypixel.com/blog/wp-content/uploads/2012/03/audiobus-tumblr.jpg" alt="Audiobus tumblr" title="audiobus-tumblr.jpg" border="0" width="250" height="197" style="float:right;" class="alignright" />I&#8217;m blogging about Audiobus&#8217;s development and other bits and pieces over on the <a href="http://audiobus.tumblr.com">Audiobus Tumblr blog</a>.</p>

<p>If you&#8217;re interested to see what I&#8217;m up to, do join me over there.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2468" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/audiobus-action-on-tumblr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some in-progress screenshots of my new project</title>
		<link>http://atastypixel.com/blog/some-in-progress-screenshots-of-my-new-project/</link>
		<comments>http://atastypixel.com/blog/some-in-progress-screenshots-of-my-new-project/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 17:29:17 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Audiobus]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mockups]]></category>
		<category><![CDATA[Screenshots]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=2456</guid>
		<description><![CDATA[It&#8217;s called &#8220;Audiobus&#8221;, and &#8212; yep, them&#8217;s big words &#8212; it&#8217;s going to change the way people create music on iOS. Here&#8217;re some mockups of the main interface… Subscribe here for more news about Audiobus as it happens.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s called &#8220;Audiobus&#8221;, and &#8212; yep, them&#8217;s big words &#8212; it&#8217;s going to change the way people create music on iOS.</p>

<p>Here&#8217;re some mockups of the main interface…</p>

<p><img style="display:block; margin-left:auto; margin-right:auto;" class="aligncenter" src="http://atastypixel.com/blog/wp-content/uploads/2012/02/a.png" alt="Audio Bus Mockup 1" title="a.png" border="0" width="260" height="209" /></p>

<p><img style="display:block; margin-left:auto; margin-right:auto;" class="aligncenter" src="http://atastypixel.com/blog/wp-content/uploads/2012/02/b.jpg" alt="b" title="b.jpg" border="0" width="552" height="189" /></p>

<p><a href="http://audiob.us">Subscribe here</a> for more news about Audiobus as it happens.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2456" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/some-in-progress-screenshots-of-my-new-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Breaking the limits: Storing data bigger than 1 Mb in Google App Engine&#8217;s Datastore</title>
		<link>http://atastypixel.com/blog/breaking-the-limits-storing-data-bigger-than-1-mb-in-google-app-engines-datastore/</link>
		<comments>http://atastypixel.com/blog/breaking-the-limits-storing-data-bigger-than-1-mb-in-google-app-engines-datastore/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 18:01:30 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/breaking-the-limits-storing-data-bigger-than-1-mb-in-google-app-engines-datastore/</guid>
		<description><![CDATA[Google App Engine is a fantastic platform for hosting webapps, and a great resource for iOS developers who need an online component to their products. It&#8217;s hard to believe that the service is essentially free! I&#8217;m using it with The Cartographer, but I found myself coming up against a hard limit with the datastore. You [...]]]></description>
			<content:encoded><![CDATA[<p>Google App Engine is a fantastic platform for hosting webapps, and a great resource for iOS developers who need an online component to their products.  It&#8217;s hard to believe that the service is essentially free!  I&#8217;m using it with <a href="http://cartographer-app.com">The Cartographer</a>, but I found myself coming up against a hard limit with the datastore.</p>

<p>You see, the <a href="http://code.google.com/appengine/docs/python/datastore/overview.html">datastore</a> limits entities to 1 Mb.  I&#8217;m trying to store XML data in there, and sometimes that can exceed the 1 Mb limit.</p>

<p>XML being the verbose creature that it is compresses very nicely, so it occurred to me that if I selectively compress the larger blocks, I should be able to quite easily squeeze in underneath the limit.  Sure enough, a 1.6 Mb XML block compressed into about 200 Kb.</p>

<p>App Engine makes it very easy to define custom properties on data models, so I&#8217;ve written a <code>CompressibleTextProperty</code> class that automatically compresses/decompresses properties above a certain size.  This means that there&#8217;s no performance loss for entities that are small enough to fit easily, but still enables the storage of bigger blocks of content.</p>

<p>The alternative was to break entities up into several different database entities, but this sounded like much more work, and sounded much less elegant.</p>

<p>So here&#8217;s what I came up with &#8212; it&#8217;s used the same way the other <a href="http://code.google.com/appengine/docs/python/datastore/datamodeling.html#Property_Classes_and_Types">Property types</a> are used.<span id="more-2108"></span>Download it here: <a href="http://atastypixel.com/blog/wp-content/uploads/2011/01/compressible_text_property.py_.txt" title="compressible_text_property.py.txt">compressible_text_property.py</a></p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># encoding: utf-8</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
compressible_text_property.py
&nbsp;
A string property that will automatically be stored compressed if larger than a given length threshold
&nbsp;
Created by Michael Tyson on 2011-01-07.
Copyright (c) 2011 A Tasty Pixel. All rights reserved.
&nbsp;
BSD LICENSE
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> db
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> datastore_types
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">zlib</span>
Text = datastore_types.<span style="color: black;">Text</span>
&nbsp;
LENGTH_THRESHOLD            = <span style="color: #ff4500;">500000</span> <span style="color: #808080; font-style: italic;"># Bytes</span>
EXPECTED_ZLIB_HEADER        = u<span style="color: #483d8b;">&quot;x<span style="color: #000099; font-weight: bold;">\x</span>9c&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> CompressibleTextProperty<span style="color: black;">&#40;</span>db.<span style="color: black;">TextProperty</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;A string property that will automatically be stored compressed if larger than a given length threshold
&nbsp;
    This is designed to be used with textual properties that may exceed App Engine's 1MB entity size limit.
    Note that, if compressed, property will not be searchable.
    &quot;&quot;&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> validate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
      <span style="color: #483d8b;">&quot;&quot;&quot;Validate text property; Nicked verbatim from TextProperty.
&nbsp;
      Returns:
        A valid value.
&nbsp;
      Raises:
        BadValueError if property is not instance of 'Text'.
      &quot;&quot;&quot;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> value <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>value, Text<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
          value = db.<span style="color: black;">Text</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">TypeError</span>, err:
          <span style="color: #ff7700;font-weight:bold;">raise</span> BadValueError<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Property %s must be convertible '</span>
                              <span style="color: #483d8b;">'to a Text instance (%s)'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">name</span>, err<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
      value = <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>db.<span style="color: black;">TextProperty</span>, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">validate</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> value <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>value, Text<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> BadValueError<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Property %s must be a Text instance'</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">return</span> value
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_value_for_datastore<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, model_instance<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;For writing to the datastore: Performs compression if length is greater than the threshold&quot;&quot;&quot;</span>
        value = <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CompressibleTextProperty, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">get_value_for_datastore</span><span style="color: black;">&#40;</span>model_instance<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> LENGTH_THRESHOLD <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> value.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span>EXPECTED_ZLIB_HEADER<span style="color: black;">&#41;</span>:
            value = <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">zlib</span>.<span style="color: black;">compress</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'ISO-8859-1'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> Text<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> make_value_from_datastore<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;For reading from the datastore: Decompresses if compressed data detected&quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> value <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> value.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span>EXPECTED_ZLIB_HEADER<span style="color: black;">&#41;</span>:
            value = <span style="color: #dc143c;">zlib</span>.<span style="color: black;">decompress</span><span style="color: black;">&#40;</span>value.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'ISO-8859-1'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> value
&nbsp;
    data_type = Text</pre></div></div>

 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2108" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/breaking-the-limits-storing-data-bigger-than-1-mb-in-google-app-engines-datastore/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy inclusion of OpenSSL into iOS projects</title>
		<link>http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/</link>
		<comments>http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 13:02:54 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/</guid>
		<description><![CDATA[Oddly, iOS doesn&#8217;t provide any OpenSSL implementation at all &#8212; If you want to do anything with crypto (like checking signatures, checksumming, etc.), you have to build in the library yourself. I came across a great XCode project wrapper for OpenSSL yesterday, by Stephen Lombardo. This is an XCode project file that contains a target [...]]]></description>
			<content:encoded><![CDATA[<p>Oddly, iOS doesn&#8217;t provide any OpenSSL implementation at all &#8212; If you want to do anything with crypto (like checking signatures, checksumming, etc.), you have to build in the library yourself.</p>

<p>I came across a great <a href="https://github.com/sjlombardo/openssl-xcode">XCode project wrapper</a> for OpenSSL yesterday, by Stephen Lombardo.  This is an XCode project file that contains a target to build OpenSSL from source, and works with both Mac and iOS projects.  I made some <a href="https://github.com/michaeltyson/openssl-xcode">modifications</a> to it, in order to make it work by just dropping in the OpenSSL source tarball, without having to dirty up your source tree with the extracted OpenSSL distribution.</p>

<p>Here&#8217;s how to use it:</p>

<ol>
<li><a href="http://www.openssl.org/source/">Download the OpenSSL source</a>.</li>
<li>Put the downloaded OpenSSL source tar.gz into the same folder
as openssl.xcodeproj (I put it in <code>Library/openssl</code> within my project tree).</li>
<li>Drag the openssl.xcodeproj file into your main project tree in XCode.</li>
<li>Right-click on your project target, and add openssl.xcodeproj under &#8220;Direct
Dependencies&#8221; on the General tab.</li>
<li><p>On the Build tab for your project&#8217;s target, find the &#8220;Header Search Paths&#8221; 
option, and add the path:</p>

<blockquote>
  <p><code>$(SRCROOT)/Library/openssl/build/openssl.build/openssl/include</code></p>
</blockquote>

<p>(Assuming you&#8217;ve put openssl.xcodeproj at the path <code>Library/openssl</code> &#8212; adjust as necessary).</p></li>
<li>Expand your target&#8217;s &#8220;Link Binary With Libraries&#8221; build stage, and drag
libcrypto.a from the openssl.xcodeproj group.</li>
</ol>

<p>Then, you can just import and use as normal (<code>#import &lt;openssl/dsa.h&gt;</code>, etc).</p>

<p><a href="https://github.com/michaeltyson/openssl-xcode/zipball/master">Download it here</a></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2100" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Avoid the clobber: Nest your network activity indicator updates</title>
		<link>http://atastypixel.com/blog/avoid-the-clobber-nest-your-network-activity-indicator-updates/</link>
		<comments>http://atastypixel.com/blog/avoid-the-clobber-nest-your-network-activity-indicator-updates/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 19:33:20 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/avoid-the-clobber-nest-your-network-activity-indicator-updates/</guid>
		<description><![CDATA[On the iPhone, when you are doing anything that uses the network, you&#8217;re supposed to let the user know something&#8217;s going on, via -[UIApplication setNetworkActivityIndicatorVisible:]. This takes a boolean. That&#8217;s all well and good, but if you have more than one object in your app that may do things with the network simultaneously, you&#8217;re going [...]]]></description>
			<content:encoded><![CDATA[<p>On the iPhone, when you are doing anything that uses the network, you&#8217;re supposed to let the user know something&#8217;s going on, via <code>-[UIApplication setNetworkActivityIndicatorVisible:]</code>.  This takes a boolean.</p>

<p>That&#8217;s all well and good, but if you have more than one object in your app that may do things with the network simultaneously, you&#8217;re going to clobber yourself.</p>

<p>A nice and easy solution: Maintain an activity counter and create a category on UIApplication to maintain it, and show or hide the indicator as appropriate.  Then, whenever you start doing something with the network:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> showNetworkActivityIndicator<span style="color: #002200;">&#93;</span>;</pre></div></div>


<p>&#8230;And when you&#8217;re done:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> hideNetworkActivityIndicator<span style="color: #002200;">&#93;</span>;</pre></div></div>


<p>Here&#8217;s a category that&#8217;ll do it:
<span id="more-2015"></span></p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> UIApplication <span style="color: #002200;">&#40;</span>TPAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>showNetworkActivityIndicator;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>hideNetworkActivityIndicator;
<span style="color: #a61390;">@end</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">static</span> NSInteger __activityCount <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
<span style="color: #a61390;">@implementation</span> UIApplication <span style="color: #002200;">&#40;</span>TPAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>showNetworkActivityIndicator <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> __activityCount <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: #002200;">&#91;</span>self setNetworkActivityIndicatorVisible<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    __activityCount<span style="color: #002200;">++</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>hideNetworkActivityIndicator <span style="color: #002200;">&#123;</span>
    __activityCount<span style="color: #002200;">--</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> __activityCount <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: #002200;">&#91;</span>self setNetworkActivityIndicatorVisible<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>
<span style="color: #a61390;">@end</span></pre></div></div>

 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2015" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/avoid-the-clobber-nest-your-network-activity-indicator-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing audio in time using Remote IO</title>
		<link>http://atastypixel.com/blog/playing-audio-in-time-using-remote-io/</link>
		<comments>http://atastypixel.com/blog/playing-audio-in-time-using-remote-io/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 20:46:38 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Loopy]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/playing-audio-in-time-using-remote-io/</guid>
		<description><![CDATA[I got an email today with a question about how to handle playback of audio in time, synchronised with a clock. My &#8216;musical notepad&#8217; app Loopy does this, and I thought I&#8217;d briefly explain how. Any app that makes use of the Remote IO audio unit framework (which is generally necessary for the kind of [...]]]></description>
			<content:encoded><![CDATA[<p>I got an email today with a question about how to handle playback of audio in time, synchronised with a clock.  My &#8216;musical notepad&#8217; app <a href="http://atastypixel.com/products/loopy">Loopy</a> does this, and I thought I&#8217;d briefly explain how.</p>

<p>Any app that makes use of the <a href="http://atastypixel.com/blog/using-remoteio-audio-unit/">Remote IO</a> audio unit framework (which is generally necessary for the kind of responsiveness required in a realtime musical app) provides audio to the hardware via a callback, which is periodically called when the hardware is ready for more.</p>

<p>The trick here is to provide the right chunk of samples in this callback for the current time position.</p>

<p>Loopy achieves this by:</p>

<h3>1. Keeping track of where in the timeline we are at the time the callback is called</h3>

<p>This is easily accomplished by keeping a record of the time the clock was started, subtracting this from the current time, and possibly performing a modulus with the tempo.  For example:</p>

<ul>
<li><code>(now - startTime) % timePerBar</code> gives the number of time units into the current bar (lets call it <code>timeIntoBar</code>).  </li>
<li><code>timeIntoBar / (timePerBar/beatsPerBar)</code> gives the number of beats into the current bar, and </li>
<li><code>timeIntoBar % (timePerBar/beatsPerBar)</code> gives us the time into the current beat.</li>
</ul>

<h3>2. Determining first if we should be playing audio at this time, and if so, which samples should be playing</h3>

<p>This involves first converting our time units from step 1 into samples.  For instance, you can convert microseconds to samples by dividing your time by <code>1000000/yourSampleRate</code>.  Aside: Of course, you can convert back from samples to time by multiplying instead of dividing.</p>

<p>Next, in the case of Loopy&#8217;s metronome, for example, we test for whether <code>samplesIntoBeat &lt; sound.lengthInSamples</code>.  If so, that means we should be playing audio.  If the sound was a loop, of course, we could be always playing.</p>

<p>The offset into the sound, in samples, is just samplesIntoBeat, in the case of the simple metronome.  In the case of a loop, you probably will be more interested in the number of samples into your loop &#8212; so instead of determining <code>(now - startTime) % timePerBar</code>, you may be interested in <code>(now - startTime) % timePerLoop</code>.</p>

<p>So, we want to return the requested number of samples starting from this offset into the sample array representing our audio.</p>

<h3>3. Returning smooth audio in time</h3>

<p>Note that if you just go returning any old set of samples, willy-nilly, you&#8217;re going to get nasty clicks and pops from discontinuities you get by not matching the start of your next buffer to the last one.</p>

<p>To ensure smoothness, Loopy keeps track of the offset of the last samples we returned, and just return the immediately following bunch of samples &#8212; unless we&#8217;re more than some threshold number of samples out of time, in which case we&#8217;ll suffer the pop in order to stay synchronised.  Actually, you can even generally avoid the pop if you smoothly blend buffers over a short time, removing any discontinuity.</p>

<h3>Final words</h3>

<p>The example above was a relatively trivial one, for a metronome sound.  For longer audio that may span multiple bars, you&#8217;ll probably want to perform a modulus by the length of your audio clip, possibly quantised to your time signature, and possibly using a per-loop time base, so you can start the loop at any point in your timeline and have it begin from the start.  This is something Loopy doesn&#8217;t currently do &#8212; Loopy will keep your loops synchronised so when you start a loop playing, it&#8217;ll play whatever part corresponds to the current timeline, not from the start of the loop. Maybe it&#8217;ll be an option in the future?</p>

<p>I wrote a little about the timing of loops in my <a href="http://atastypixel.com/blog/developing-loopy-part-2-implementation/">second article on Loopy&#8217;s implementation</a>.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1993" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/playing-audio-in-time-using-remote-io/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone debugging tip: Breaking on exceptions and reading their content</title>
		<link>http://atastypixel.com/blog/iphone-debugging-tip-breaking-on-exceptions-and-reading-their-content/</link>
		<comments>http://atastypixel.com/blog/iphone-debugging-tip-breaking-on-exceptions-and-reading-their-content/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 21:23:12 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/iphone-debugging-tip-breaking-on-exceptions-and-reading-their-content/</guid>
		<description><![CDATA[Just a quick one: This may be obvious to many devs, but it&#8217;s worth noting. One common and useful debugging technique is breaking on exceptions, so that you can see exactly where in your app&#8217;s flow a breakpoint occurs. This can be done by adding -[NSException raise] and objc_exception_throw to your breakpoints list. Once an [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick one: This may be obvious to many devs, but it&#8217;s worth noting.  One common and useful <a href="http://www.cocoadev.com/index.pl?DebuggingTechniques">debugging technique</a> is breaking on exceptions, so that you can see exactly where in your app&#8217;s flow a breakpoint occurs.</p>

<p>This can be done by adding <code>-[NSException raise]</code> and <code>objc_exception_throw</code> to your breakpoints list.</p>

<p>Once an exception happens, you can then check out the exception itself to see what went wrong.  The approach varies between platforms. If you&#8217;re in the simulator (or any Mac OS X app running on Intel), the exception will be stored in the <code>$eax</code> register.  Take a look by typing:</p>

<p><code>po $eax</code></p>

<p>If you&#8217;re on the iPhone, it&#8217;ll be <code>$r0</code>, so:</p>

<p><code>po $r0</code></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1991" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/iphone-debugging-tip-breaking-on-exceptions-and-reading-their-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone/Mac animation for custom classes: Property animation for more than just CALayer</title>
		<link>http://atastypixel.com/blog/key-path-based-property-animation/</link>
		<comments>http://atastypixel.com/blog/key-path-based-property-animation/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 20:38:18 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/key-path-based-property-animation/</guid>
		<description><![CDATA[An Objective-C class that provides similar functionality to CABasicAnimation, but works on any object.]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a custom view &#8212; a 3D vintage-looking pull lever &#8212; that provided a continuous property to control the state.  I wanted to animated this smoothly, a-la CABasicAnimation, but couldn&#8217;t find a built-in way to do so.</p>

<p>So, I wrote a class that provides similar functionality to CABasicAnimation, but works on any object.  I thought I&#8217;d share it.</p>

<p>Features:</p>

<ul>
<li>From/to value settings (currently only supports <code>NSNumber</code> and scalar numeric types, but easily extendable)</li>
<li>Duration, delay settings</li>
<li>Timing functions: Linear, ease out, ease in, and ease in/ease out</li>
<li>Animation chaining (specify another configured animation for <code>chainedAnimation</code>, and it&#8217;ll be fired once the first animation completes)</li>
<li>Delegate notification of animation completion</li>
<li>Uses a single timer for smooth lock-step animation</li>
<li>Uses <code>CADisplayLink</code> if available, to update in sync with screen updates</li>
</ul>

<p>Use it like this:</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>startMyAnimation <span style="color: #002200;">&#123;</span>
  TPPropertyAnimation <span style="color: #002200;">*</span>animation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>TPPropertyAnimation propertyAnimationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;state&quot;</span><span style="color: #002200;">&#93;</span>;
  animation.toValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// fromValue is taken from current value if not specified</span>
  animation.duration <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span>;
  animation.timing <span style="color: #002200;">=</span> TPPropertyAnimationTimingEaseIn;
  <span style="color: #002200;">&#91;</span>animation beginWithTarget<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>


<p>Make sure you also include the QuartzCore framework, used to access <code>CADisplayLink</code>, if it&#8217;s available.</p>

<p>It&#8217;s BSD-licensed.</p>

<p>Grab it here: 
<a href="http://atastypixel.com/blog/wp-content/uploads/2010/08/TPPropertyAnimation.zip" title="TPPropertyAnimation.zip">TPPropertyAnimation.zip</a></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1973" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/key-path-based-property-animation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for May 30th through August 8th</title>
		<link>http://atastypixel.com/blog/links-may-30th-august-8th/</link>
		<comments>http://atastypixel.com/blog/links-may-30th-august-8th/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 22:00:37 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1921</guid>
		<description><![CDATA[Links for May 30th through August 8th: cuf&#243;n &#8211; fonts for the people A very impressive framework that embeds any font into a website, via javascript and the canvas element. Great cross-browser support. mikeash.com: Method Replacement for Fun and Profit Method replacement and method swizzling in Objective-C. Core Data Tutorial: How To Use NSFetchedResultsController &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Links for May 30th through August 8th:</p>

<ul class="delicious-bookmarks">
<li><a href="http://cufon.shoqolate.com/generate/">cuf&oacute;n &#8211; fonts for the people</a> A very impressive framework that embeds any font into a website, via javascript and the canvas element. Great cross-browser support.</li>
<li><a href="http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html">mikeash.com: Method Replacement for Fun and Profit</a> Method replacement and method swizzling in Objective-C.</li>
<li><a href="http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller">Core Data Tutorial: How To Use NSFetchedResultsController | Ray Wenderlich</a> </li>
<li><a href="http://github.com/akosma/TwitThis">TwitThis &ndash; Use Multiple Twitter Clients on your iPhone Application</a> The class TwitterClientManager loads a list list of supported Twitter clients is loaded from a plist file, which can be extended to support more clients in the future;<br />
Each Twitter client is represented by an instance of the TwitterClient class;<br />
The user can choose his preferred Twitter client at any time, and launch the application by a simple touch; the TwitterClientManager class stores the selected value in the user settings.</li>

</ul>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1921" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/links-may-30th-august-8th/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Achieve smaller app downloads by replacing large PNGs with JPEG + mask</title>
		<link>http://atastypixel.com/blog/achieve-smaller-app-downloads-by-replacing-large-pngs-with-jpeg-mask/</link>
		<comments>http://atastypixel.com/blog/achieve-smaller-app-downloads-by-replacing-large-pngs-with-jpeg-mask/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 00:26:17 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Optimisation]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1967</guid>
		<description><![CDATA[I&#8217;m using a transparent overlay on top of a fairly common interface element to make it look awesome. I originally did this with a transparent PNG, until I realised the PNG in question for the iPhone 4&#8242;s Retina display was truly massive, clocking in at 1 Mb. Why we don&#8217;t have common image format with [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using a transparent overlay on top of a fairly common interface element to make it look awesome.  I originally did this with a transparent PNG, until I realised the PNG in question for the iPhone 4&#8242;s Retina display was truly massive, clocking in at 1 Mb.</p>

<p>Why we don&#8217;t have common image format with both transparency and lossy compression is beyond me, but there&#8217;s a relatively easy alternative: Using a JPEG and masking it with another JPEG.</p>

<p>Based on Rodney Aiglstorfer&#8217;s solution on <a href="http://iPhoneDeveloperTips.com/cocoa/how-to-mask-an-image.html">how to mask an image</a>, I derived a category on UIImage which would apply a mask to an image.  The method required a little tweaking to work with JPEG images &#8212; the <code>CGImageCreateWithMask</code> function won&#8217;t work correctly on source images that don&#8217;t have an alpha channel, so one has to create one first, from the original.  Jean Regisser figured out the <a href="http://pastie.org/418627">solution</a> which he presents in a comment on the above article, but it needs one more addition: A check on line 37 for <code>kCGImageAlphaNoneSkipLast</code>. <em>Update: Oh, and one more &#8211; kCGImageAlphaNoneSkipFirst</em></p>

<p>So, the complete category for applying a mask to a JPEG image, to achieve the same result as using a PNG but with less download time for your users:</p>

<p><span id="more-1967"></span></p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Header</span>
&nbsp;
<span style="color: #a61390;">@interface</span> UIImage <span style="color: #002200;">&#40;</span>TPAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>imageByMaskingUsingImage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIImage <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>maskImage;
<span style="color: #a61390;">@end</span>
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Implementation</span>
&nbsp;
CGImageRef CopyImageAndAddAlphaChannel<span style="color: #002200;">&#40;</span>CGImageRef sourceImage<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    CGImageRef retVal <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
&nbsp;
    <span style="color: #a61390;">size_t</span> width <span style="color: #002200;">=</span> CGImageGetWidth<span style="color: #002200;">&#40;</span>sourceImage<span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">size_t</span> height <span style="color: #002200;">=</span> CGImageGetHeight<span style="color: #002200;">&#40;</span>sourceImage<span style="color: #002200;">&#41;</span>;
&nbsp;
    CGColorSpaceRef colorSpace <span style="color: #002200;">=</span> CGColorSpaceCreateDeviceRGB<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    CGContextRef offscreenContext <span style="color: #002200;">=</span> CGBitmapContextCreate<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span>, width, height, 
                                                          <span style="color: #2400d9;">8</span>, <span style="color: #2400d9;">0</span>, colorSpace, kCGImageAlphaPremultipliedFirst<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>offscreenContext <span style="color: #002200;">!=</span> <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        CGContextDrawImage<span style="color: #002200;">&#40;</span>offscreenContext, CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, width, height<span style="color: #002200;">&#41;</span>, sourceImage<span style="color: #002200;">&#41;</span>;
&nbsp;
        retVal <span style="color: #002200;">=</span> CGBitmapContextCreateImage<span style="color: #002200;">&#40;</span>offscreenContext<span style="color: #002200;">&#41;</span>;
        CGContextRelease<span style="color: #002200;">&#40;</span>offscreenContext<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    CGColorSpaceRelease<span style="color: #002200;">&#40;</span>colorSpace<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> retVal;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@implementation</span> UIImage <span style="color: #002200;">&#40;</span>TPAdditions<span style="color: #002200;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>imageByMaskingUsingImage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIImage <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>maskImage <span style="color: #002200;">&#123;</span>
&nbsp;
    CGImageRef maskRef <span style="color: #002200;">=</span> maskImage.CGImage; 
    CGImageRef mask <span style="color: #002200;">=</span> CGImageMaskCreate<span style="color: #002200;">&#40;</span>CGImageGetWidth<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>,
                                        CGImageGetHeight<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>,
                                        CGImageGetBitsPerComponent<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>,
                                        CGImageGetBitsPerPixel<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>,
                                        CGImageGetBytesPerRow<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>,
                                        CGImageGetDataProvider<span style="color: #002200;">&#40;</span>maskRef<span style="color: #002200;">&#41;</span>, <span style="color: #a61390;">NULL</span>, <span style="color: #a61390;">false</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    CGImageRef source <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self CGImage<span style="color: #002200;">&#93;</span>;
&nbsp;
    NSInteger alphaInfo <span style="color: #002200;">=</span> CGImageGetAlphaInfo<span style="color: #002200;">&#40;</span>source<span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> alphaInfo <span style="color: #002200;">==</span> kCGImageAlphaNone || alphaInfo <span style="color: #002200;">==</span> kCGImageAlphaNoneSkipLast || alphaInfo <span style="color: #002200;">==</span> kCGImageAlphaNoneSkipFirst <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        source <span style="color: #002200;">=</span> CopyImageAndAddAlphaChannel<span style="color: #002200;">&#40;</span>source<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    CGImageRef masked <span style="color: #002200;">=</span> CGImageCreateWithMask<span style="color: #002200;">&#40;</span>source, mask<span style="color: #002200;">&#41;</span>;
    CGImageRelease<span style="color: #002200;">&#40;</span>mask<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> source <span style="color: #002200;">!=</span> <span style="color: #002200;">&#91;</span>self CGImage<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        CGImageRelease<span style="color: #002200;">&#40;</span>source<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    UIImage <span style="color: #002200;">*</span>result;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>UIImage respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>imageWithCGImage<span style="color: #002200;">:</span>scale<span style="color: #002200;">:</span>orientation<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>masked scale<span style="color: #002200;">:</span>self.scale orientation<span style="color: #002200;">:</span>self.imageOrientation<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>masked<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    CGImageRelease<span style="color: #002200;">&#40;</span>masked<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> result;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>


<p>Note that the image mask should be another JPEG (or PNG, if you really like), without transparency, and greyscale, where black represents full opacity, and white represents full transparency.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1967" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/achieve-smaller-app-downloads-by-replacing-large-pngs-with-jpeg-mask/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Reginald RegEx explorer</title>
		<link>http://atastypixel.com/blog/reginald-regex-explorer/</link>
		<comments>http://atastypixel.com/blog/reginald-regex-explorer/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 22:28:27 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/reginald-regex-explorer/</guid>
		<description><![CDATA[With a desperate need to debug a lengthy regular expression destined for use with the excellent RegexKitLite library, I have quickly put together a Mac OS X application. Reginald is a kindly old gentleman devoted to assisting you with those tricky regular expressions. Provide some sample input, and your regular expression, and Reginald will provide [...]]]></description>
			<content:encoded><![CDATA[<p>With a desperate need to debug a lengthy regular expression destined for use with the excellent <a href="http://regexkit.sourceforge.net/RegexKitLite/">RegexKitLite</a> library, I have quickly put together a Mac OS X application.</p>

<p><img src="http://atastypixel.com/blog/wp-content/uploads/2010/07/reg.png" width="64" height="69" alt="Reginald icon" style="float:right;" />
Reginald is a kindly old gentleman devoted to assisting you with those tricky regular expressions.</p>

<p>Provide some sample input, and your regular expression, and Reginald will provide you with colour-coded output and a list of all your matches and the corresponding capture groups for your exploration.  Select a match or capture group in the list to the right, and the corresponding text will be selected in the panel to the left.</p>

<p>Reginald is built on <a href="http://regexkit.sourceforge.net/RegexKitLite/">RegexKitLite</a>, and so uses the <a href="http://regexkit.sourceforge.net/RegexKitLite/index.html#ICUSyntax">ICU syntax</a>.</p>

<p>It will run on Mac OS X 10.6 and above.</p>

<p><a href="http://github.com/michaeltyson/Reginald/downloads">Download Reginald here</a>, or <a href="http://github.com/michaeltyson/Reginald">access the source on GitHub</a>.</p>

<p><a href="http://atastypixel.com/blog/wp-content/uploads/2010/07/201007312318.jpg" rel="lightbox[1966]"><img src="http://atastypixel.com/blog/wp-content/uploads/2010/07/201007312318-tm.jpg" width="450" height="342" alt="Reginald screenshot" class="aligncenter" /></a></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1966" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/reginald-regex-explorer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Making UIToolbar and UINavigationBar&#8217;s background totally transparent</title>
		<link>http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/</link>
		<comments>http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 10:14:02 +0000</pubDate>
		<dc:creator>Michael Tyson</dc:creator>
				<category><![CDATA[Geekspeak]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1959</guid>
		<description><![CDATA[Technique to make the background of UIToolbar and UINavigationBar transparent, for custom interfaces]]></description>
			<content:encoded><![CDATA[<p>I have an upcoming iPhone application, <a href="http://atastypixel.com/products/cartographer">Cartographer</a>, that is highly stylised and requires high customisation of the interface to achieve a convincing, beautiful vintage look.  To make it work, I needed transparent toolbars and navigation bars for my UIViewController-based views.</p>

<p>The solution I came up with for this was to implement a category on UINavigationBar and UIToolbar, and overriding <code>drawRect:</code> with a method that does absolutely nothing.  Then I can place my own textures behind the bar, and they&#8217;ll be seen, instead of the default bar background.<span id="more-1959"></span></p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> UINavigationBar <span style="color: #002200;">&#40;</span>TransparentAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #a61390;">@end</span>
<span style="color: #a61390;">@implementation</span> UINavigationBar <span style="color: #002200;">&#40;</span>TransparentAdditions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Do nothing!</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>


<p>For UIToolBar, if you&#8217;re using it within a UINavigationController, you&#8217;ll want to also override <code>drawLayer:inContext:</code>, as this appears to be used instead of <code>drawRect:</code> when used within a navigation controller, for some weird reason.</p>

<p>Note that this method will affect <em>all</em> bars in your app. If you only want <em>some</em> bars to be transparent, you&#8217;ll need to do a little objc-hocus-pocus.  Thanks to Mike Ash for this solution on <a href="http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html">method replacement</a> (read that article for the whys and hows).  This technique replaces the default methods as before, but keeps track of the defaults.  If you now set the <code>tintColor</code> of the bar to <code>[UIColor clearColor]</code>, the bar will have a transparent background.  Otherwise, it&#8217;ll just look the same as usual.</p>

<p>For UIToolbar (same principle for UINavigationBar):</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;objc/runtime.h&gt;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Keep track of default implementation</span>
<span style="color: #a61390;">static</span> <span style="color: #a61390;">void</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">*</span>_origDrawRect<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span>, <span style="color: #a61390;">SEL</span>, CGRect<span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">static</span> <span style="color: #a61390;">void</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">*</span>_origDrawLayerInContext<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span>, <span style="color: #a61390;">SEL</span>, CALayer<span style="color: #002200;">*</span>, CGContextRef<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Override for drawRect:</span>
<span style="color: #a61390;">static</span> <span style="color: #a61390;">void</span> OverrideDrawRect<span style="color: #002200;">&#40;</span>UIToolbar <span style="color: #002200;">*</span>self, <span style="color: #a61390;">SEL</span> _cmd, CGRect r<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self tintColor<span style="color: #002200;">&#93;</span> isEqual<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;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// Do nothing</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// Call default method</span>
        _origDrawRect<span style="color: #002200;">&#40;</span>self, _cmd, r<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Override for drawLayer:inContext:</span>
<span style="color: #a61390;">static</span> <span style="color: #a61390;">void</span> OverrideDrawLayerInContext<span style="color: #002200;">&#40;</span>UIToolbar <span style="color: #002200;">*</span>self, <span style="color: #a61390;">SEL</span> _cmd, CALayer <span style="color: #002200;">*</span>layer, CGContextRef context<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self tintColor<span style="color: #002200;">&#93;</span> isEqual<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;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// Do nothing</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// Call default method</span>
        _origDrawLayerInContext<span style="color: #002200;">&#40;</span>self, _cmd, layer, context<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@implementation</span> UIToolbar <span style="color: #002200;">&#40;</span>TransparentAdditions<span style="color: #002200;">&#41;</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>load <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Replace methods, keeping originals</span>
    Method origMethod <span style="color: #002200;">=</span> class_getInstanceMethod<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
    _origDrawRect <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>method_getImplementation<span style="color: #002200;">&#40;</span>origMethod<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>class_addMethod<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">IMP</span><span style="color: #002200;">&#41;</span>OverrideDrawRect, method_getTypeEncoding<span style="color: #002200;">&#40;</span>origMethod<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
        method_setImplementation<span style="color: #002200;">&#40;</span>origMethod, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">IMP</span><span style="color: #002200;">&#41;</span>OverrideDrawRect<span style="color: #002200;">&#41;</span>;
&nbsp;
    origMethod <span style="color: #002200;">=</span> class_getInstanceMethod<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>drawLayer<span style="color: #002200;">:</span>inContext<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
    _origDrawLayerInContext <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>method_getImplementation<span style="color: #002200;">&#40;</span>origMethod<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>class_addMethod<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>drawLayer<span style="color: #002200;">:</span>inContext<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">IMP</span><span style="color: #002200;">&#41;</span>OverrideDrawLayerInContext, method_getTypeEncoding<span style="color: #002200;">&#40;</span>origMethod<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
        method_setImplementation<span style="color: #002200;">&#40;</span>origMethod, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">IMP</span><span style="color: #002200;">&#41;</span>OverrideDrawLayerInContext<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>


<p>You can now add background texture to the bars in a number of ways. These are two I&#8217;ve used:</p>

<ul>
<li>By adding a CALayer to <code>[bar layer]</code> &#8212; but note that UINavigationBar will try to add elements at index 0, underneath your background.  To make this work, I provided a subclassed CALayer (and overrode UINavigationBar&#8217;s <code>+layer</code> method) which only lets <em>you</em> insert layers at index 0, via a custom method, and override <code>insertLayer:atIndex:</code> method, setting index to 1 if it&#8217;s 0.  UIToolbar doesn&#8217;t require this.</li>
<li>Or, by adding a CALayer to your view layer.  Note that the view&#8217;s bounds do not cover the UINavigationBar; I had to offset the layer by the height of the bar in question (<code>navigationBarLayer.frame = CGRectMake(0, -self.navigationController.navigationBar.frame.size.height, [barImage size].width, [barImage size].height);</code>, for example), and set <code>self.view.clipsToBounds = NO</code> to allow the layer to be seen.</li>
</ul>

<p>Of course, you can also draw the texture in <code>drawRect:</code>, instead.  It&#8217;s entirely up to you.  The advantage in using a <code>CALayer</code> is that it can overlap the view boundary, for effects like drop shadows.</p>

<p><img src="http://atastypixel.com/blog/wp-content/uploads/2010/07/201007191118.jpg" width="320" height="84" alt="201007191118.jpg" class="aligncenter" /></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1959" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>

