<?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>Chris-Software.com &#187; alpha</title>
	<atom:link href="http://chris-software.com/index.php/tag/alpha/feed/" rel="self" type="application/rss+xml" />
	<link>http://chris-software.com</link>
	<description>iPhone, iPod touch games, Objective-C Tutorials, krzysztofrutkowski.com</description>
	<lastBuildDate>Tue, 29 Mar 2011 09:58:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Colors</title>
		<link>http://chris-software.com/index.php/2009/04/27/colors/</link>
		<comments>http://chris-software.com/index.php/2009/04/27/colors/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 22:16:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Obj-C Tutorials]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[colour]]></category>
		<category><![CDATA[RGB]]></category>
		<category><![CDATA[RGB colors]]></category>
		<category><![CDATA[textures]]></category>
		<category><![CDATA[Transparent]]></category>
		<category><![CDATA[UIColor]]></category>

		<guid isPermaLink="false">http://chris-software.com/?page_id=651</guid>
		<description><![CDATA[Most colors you will set in Interface Builder rather than in Xcode on the beginning, but if you need to change it dynamically, I&#8217;m sorry you need to know it.
I will present you the way how to change the background color of UIImageView &#8211; in other words image, using UIColor. By image I mean simply [...]]]></description>
			<content:encoded><![CDATA[<p>Most colors you will set in <em>Interface Builder</em> rather than in <em>Xcode</em> on the beginning, but if you need to change it dynamically, I&#8217;m sorry you need to know it.</p>
<p>I will present you the way how to change the background color of <em>UIImageView</em> &#8211; in other words image, using <em>UIColor</em>. By <em>image</em> I mean simply placeholder for <em>image</em>, because <em>UIImageView</em> can be just a colored rectangle without any PNG/JPG at all. But <em>UIColor</em> is very flexible, using the same code, you can change not only background colors, but shadow <em>shadowColor</em> (for <em>UILabel</em>), <em>textColor</em> (also <em>UILabel</em>) and I&#8217;m sure there is even more <em>properties </em>I can&#8217;t remember in this particular moment.</p>
<p>The code is very simple (as usuall):</p>
<pre>myImage.backgroundColor = [UIColor blueColor];</pre>
<p>Above code will cause, that <em>myImage&#8217;s</em> frame will be blue.</p>
<p>You can experiment with a lot of colors like:</p>
<ul>
<li><em>blackColor</em></li>
<li><em>brownColor</em></li>
<li><em>cyanColor</em></li>
<li><em>grayColor</em></li>
<li><em>greenColor</em></li>
<li>&#8230;</li>
</ul>
<p>While in <em>Xcode</em> write <em>&#8220;[UIColor "</em> and press escape to a list of all possible ending and you will get a lot of standard colors you can use.</p>
<p>If you would like to make your <em>image</em> (or anything else) transparent in some percent you can use <em>alpha</em> property:</p>
<pre>myImage.alpha = 0.5;</pre>
<p>This will make your <em>image</em> half transparent.</p>
<h2>RGB</h2>
<p>Of course it's not all. iPhone / iPod touch are devices able to display millions of colors (so they said). I have never counted them but it's very easy to display any color giving the amount of <em>red</em>, <em>green</em> and <em>blue</em>... and alpha at once.</p>
<p>The code is also a single line:</p>
<pre><span>	</span><span>image</span>.backgroundColor = [<span>UIColor</span> <span>colorWithRed</span>:121/<span>255</span> <span>green</span>:42/<span>255</span> <span>blue</span>:120/<span>255</span> <span>alpha</span>:0.9];</pre>
<div>Above sets the image's frame color <em>RGB(121,42,120</em>) which opacity is 90%. You need to know one thing about above structure especially the alpha part. If you set this <em>color</em> as a <em>backgroundColor</em> for <em>UILabel</em>, only the background will be transparent in 10%, the text will be visible in 100%.</div>
<h2><strong>Predefined textures</strong></h2>
<div>There are already to predefined textures you can use as a color. They are:</div>
<div style="text-align: center;"><em>viewFlipsideBackgroundColor<br />
<a href="http://chris-software.com/wp-content/uploads/2009/04/flipsidetexture.png"><img class="alignnone size-full wp-image-652" title="flipsidetexture" src="http://chris-software.com/wp-content/uploads/2009/04/flipsidetexture.png" alt="flipsidetexture" width="100" height="50" /></a></em></div>
<div style="text-align: center;"><em>groupTableViewBackgroundColor<br />
<a href="http://chris-software.com/wp-content/uploads/2009/04/groupedtexture.png"><img class="alignnone size-full wp-image-653" title="groupedtexture" src="http://chris-software.com/wp-content/uploads/2009/04/groupedtexture.png" alt="groupedtexture" width="100" height="50" /></a></em></p>
<p style="text-align: left;"><span style="font-style: normal;"><em>Depending of brightness of your screen</em></span><em> viewFlipsideBackgroundColor<span style="font-style: normal;"> looks like some kind of black material. I guess every iPhone user is familiar with the second one, it's the same background as </span>grouped UITableView<span style="font-style: normal;"> uses (see </span>Settings<span style="font-style: normal;"> application). You can use them like they were a normal color.</span></em></p>
<pre style="text-align: left;"><em>myImage.backgroundColor = [UIColor viewFlipsideBackgroundColor];
myImage.backgroundColor = [UIColor groupTableViewBackgroundColor];</em></pre>
<h2 style="text-align: left;"><span style="font-style: normal;"><em>One more thing</em></span></h2>
<p style="text-align: left;"><span style="font-style: normal;"><em>There is an interesting color </em></span><em>clearColor<span style="font-style: normal;">. What does it to? Well maybe it wan't be important right now, as long as you can change any object's property </span>alpha<span style="font-style: normal;"> to </span>zero<span style="font-style: normal;">. But </span>clearColor<span style="font-style: normal;"> will simply erase any color, very helpful in 2D graphics (</span>Quartz<span style="font-style: normal;">).</span></em></p>
<h2 style="text-align: left;"><span style="font-style: normal;"><em>Another one more thing</em></span></h2>
<p style="text-align: left;"><span style="font-style: normal;"><em>As usuall I prepared for you a project. An application where you can test any color you need changing the <strong>RGB</strong> and <strong>alpha</strong> using sliders and the preview of </em></span><em>viewFlipsideBackgroundColor<span style="font-style: normal;"> and </span>groupTableViewBackgroundColor<span style="font-style: normal;">.</span></em></p>
<p style="text-align: center;"><span style="font-style: normal;"><span style="color: #0000ee; font-style: normal; text-decoration: underline;"><em><a href="http://chris-software.com/wp-content/uploads/2009/04/colors.zip"><img class="alignnone size-full wp-image-564" title="xcodeproj" src="http://chris-software.com/wp-content/uploads/2009/04/xcodeproj.png" alt="xcodeproj" width="128" height="128" /></a></em></span></span></p>
<p style="text-align: center;"><span style="font-style: normal;"><em><em> </em><a href="http://chris-software.com/wp-content/uploads/2009/04/colors.zip">Download </a><em><span style="font-style: normal;"><a href="http://chris-software.com/wp-content/uploads/2009/04/colors.zip">the project</a></span></em></em></span></p>
<p style="text-align: center;"><span style="color: #0000ee; font-style: normal; text-decoration: underline;"><em><img class="alignnone size-medium wp-image-655" title="colorssimulator" src="http://chris-software.com/wp-content/uploads/2009/04/colorssimulator-161x300.png" alt="colorssimulator" width="161" height="300" /></em></span></p>
<p><em> </em></div>
]]></content:encoded>
			<wfw:commentRss>http://chris-software.com/index.php/2009/04/27/colors/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

