<?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>yacana</title>
	<atom:link href="http://www.yacana.ro/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yacana.ro</link>
	<description>About my passions</description>
	<lastBuildDate>Tue, 28 Feb 2012 09:28:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Objective C: Extract portion of a string using NSRange</title>
		<link>http://www.yacana.ro/objective-c-extract-portion-of-a-string-using-nsrange/</link>
		<comments>http://www.yacana.ro/objective-c-extract-portion-of-a-string-using-nsrange/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 09:09:19 +0000</pubDate>
		<dc:creator>octavian</dc:creator>
				<category><![CDATA[Objective-c]]></category>

		<guid isPermaLink="false">http://www.yacana.ro/?p=69</guid>
		<description><![CDATA[Currently working on an app that requires me to parse the contents of a web page, extract a string from it and make an array. The &#8220;make an array part&#8221; is simple because the string is separated by commas and NSString has a method for generating an array of items separated by a certain string [...]]]></description>
			<content:encoded><![CDATA[<p>Currently working on an app that requires me to parse the contents of a web page, extract a string from it and make an array. The &#8220;make an array part&#8221; is simple because the string is separated by commas and NSString has a method for generating an array of items separated by a certain string &#8211; componentSeparatedByString:. The part with &#8220;getting the string I need&#8221; is a bit less straight-forward though. So let&#8217;s say that this is the HTML of the web page I have to parse:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;&lt;<a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">meta</span></a> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Pragma&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;no-cache&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span>1,1,5,100,1,64,foo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>What I actually need is the bit between the opening and closing &lt;body&gt; tags. I shall paste my solution here and will explain it step by step:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>originalString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;html&gt;&lt;meta http-equiv=&quot;</span>Pragma<span style="color: #bf1d1a;">&quot; content=&quot;</span>no<span style="color: #002200;">-</span>cache<span style="color: #bf1d1a;">&quot;&gt;&lt;/head&gt;&lt;body&gt;1,1,5,100,1,64,foo&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #a61390;">NSRange</span> startingRange <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>originalString rangeOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;body&gt;&quot;</span> options<span style="color: #002200;">:</span>NSBackwardsSearch<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #a61390;">NSRange</span> endingRange <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>originalString rangeOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/body&gt;&quot;</span> options<span style="color: #002200;">:</span>NSBackwardsSearch<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #a61390;">int</span>  myRangeLenght <span style="color: #002200;">=</span> endingRange.location <span style="color: #002200;">-</span> startingRange.location;<br />
<span style="color: #a61390;">NSRange</span> myStringRange <span style="color: #002200;">=</span> NSMakeRange <span style="color: #002200;">&#40;</span>startingRange.location, myRangeLength<span style="color: #002200;">&#41;</span>;<br />
<br />
NSLog <span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;My new string is %@&quot;</span>, <span style="color: #002200;">&#91;</span>originalString substringWithRange<span style="color: #002200;">:</span>myStringRange<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>In the first line I am creating a new string object of type NSString.</p>
<p>Next I am defining two NSRange data structures. NSRange is a Foundation data type reference used to determine ranges in strings or arrays. It has 2 fields: location and length. So in the second line I am basically asking the compiler to give me the range of &lt;body&gt; string located in my originalString. I am then asking the compiler to give me another range for the closing &lt;/body&gt; tag. At this point I have 2 ranges that don&#8217;t really do much on their own. But having the starting and ending point of a segment I can figure out the length of the segment. </p>
<p>This is exactly what I am doing on the 4th line &#8211; substracting <em>startingRange.location</em> from <em>endingRange.location</em> gives me that exact length. And after I have the length I can very well make a new range that defines the portion of the string that I am interested in. Making a new range is easy and it&#8217;s done with <strong>NSMakeRange</strong>.</p>
<p>The NSLog will return <strong>&lt;body&gt;1,1,5,100,1,64,foo </strong>and this is perfect because I am only interested in the &#8220;foo&#8221; part of the entire string so I don&#8217;t care about the tangling &lt;body&gt; part of it. But it can ofc be refined to whatever fits your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yacana.ro/objective-c-extract-portion-of-a-string-using-nsrange/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Photoshop: Creating realistic hair with Photoshop standard brushes</title>
		<link>http://www.yacana.ro/photoshop-creating-realistic-hair-with-photoshop-standard-brushes/</link>
		<comments>http://www.yacana.ro/photoshop-creating-realistic-hair-with-photoshop-standard-brushes/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 13:44:54 +0000</pubDate>
		<dc:creator>octavian</dc:creator>
				<category><![CDATA[Photoshop]]></category>

		<guid isPermaLink="false">http://www.yacana.ro/?p=59</guid>
		<description><![CDATA[I am currently working on a new exciting project and it involves removing background from a lot of pics featuring animals. It&#8217;s more or less easy to cut an object with straight edges from a photo but it becomes a little bit tricky when hair is involved. This short tutorial is mostly adressed to people [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a new exciting project and it involves removing background from a lot of pics featuring animals. It&#8217;s more or less easy to cut an object with straight edges from a photo but it becomes a little bit tricky when hair is involved. This short tutorial is mostly adressed to people that have more than basic Photoshop knowledge. I won&#8217;t be going in too many details regarding use of tools. So here is the original photo of a cat:</p>
<p><img class="alignnone size-full wp-image-60" title="original cat" src="http://www.yacana.ro/wp-content/uploads/2012/02/1.jpg" alt="" width="800" height="654" /></p>
<p>First thing I did was to use my pen tool and remove the background. The result was as follows:</p>
<p><img class="alignnone size-full wp-image-61" title="cat cut" src="http://www.yacana.ro/wp-content/uploads/2012/02/2.jpg" alt="" width="800" height="654" /></p>
<p>As you can probably notice it&#8217;s all good except the fact that the cat&#8217;s fur doesn&#8217;t look too natural. In order to make fur I didn&#8217;t use any complex hair brushes. I used a standard ( I guess it&#8217;s usually called &#8220;grass&#8221; brush ):</p>
<p><img class="aligncenter size-full wp-image-62" title="brushes" src="http://www.yacana.ro/wp-content/uploads/2012/02/2.5.png" alt="" width="282" height="273" /></p>
<p>In the brush editor one can make all kinds of amazing effects from a boring round brush by affecting scatter ratio, size ratio etc. It is also possible to change the brush angle. This is the only &#8220;trick&#8221; I used for this effect. So on a layer behind the cat I painted on the edge. Brush size is important of course but it depends on the animal you&#8217;re trying to retouch. In my case I used a fairly small size. I also used a tablet for this as it makes things a lot easier.</p>
<p><img class="alignnone size-full wp-image-63" title="angle adjustment" src="http://www.yacana.ro/wp-content/uploads/2012/02/3.jpg" alt="" width="800" height="580" /></p>
<p>The color of the brush is not really important. I set it to a color closer to the cat&#8217;s fur because I wanted to get a feel of the final comp. At this point I had the right fur but I didn&#8217;t have the right color. For the color I basically made a clipping mask from the fur layer and on the layer on top I used the clone stamp tool to copy fur features from the actual cat to my new layer:</p>
<p><img class="alignnone size-full wp-image-64" title="cat fur better" src="http://www.yacana.ro/wp-content/uploads/2012/02/4.png" alt="" width="800" height="450" /></p>
<p>In the end after a few more adjustments I had a cat with transparent background and natural looking fur. I also added a few adjustment layers because I didn&#8217;t like the original color.</p>
<p><img class="alignnone size-full wp-image-65" title="Cat retouched" src="http://www.yacana.ro/wp-content/uploads/2012/02/5.jpg" alt="" width="800" height="654" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yacana.ro/photoshop-creating-realistic-hair-with-photoshop-standard-brushes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objective C: Navigating between views with dynamically generated buttons</title>
		<link>http://www.yacana.ro/objective-c-navigating-between-views-with-dynamically-generated-buttons/</link>
		<comments>http://www.yacana.ro/objective-c-navigating-between-views-with-dynamically-generated-buttons/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 23:05:30 +0000</pubDate>
		<dc:creator>octavian</dc:creator>
				<category><![CDATA[Objective-c]]></category>

		<guid isPermaLink="false">http://www.yacana.ro/?p=53</guid>
		<description><![CDATA[It&#8217;s easy enough to navigate from a manually added button to a specific View in the MainStoryboard. But it&#8217;s a little less straightforward when such an action is required off dynamically generated controls. The past few days this is what I&#8217;ve been crunching on  and here is the solution I finally got to. First off [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy enough to navigate from a manually added button to a specific View in the MainStoryboard. But it&#8217;s a little less straightforward when such an action is required off dynamically generated controls. The past few days this is what I&#8217;ve been crunching on  and here is the solution I finally got to.</p>
<p>First off I created a button:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>self makeThumbnail<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><br />
atPosX<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><br />
atPosY<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><br />
withSizeW<span style="color: #002200;">:</span><span style="color: #2400d9;">200</span><br />
withSizeH<span style="color: #002200;">:</span><span style="color: #2400d9;">50</span><br />
withTag<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><br />
inView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>Inside the method that generates the button I also have a line that adds a specific action to it.</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>myButton addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>pushToNextView<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>And the called method:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>pushToNextView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span><br />
<span style="color: #002200;">&#91;</span>self performSegueWithIdentifier<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;loadNextViewSegue&quot;</span> sender<span style="color: #002200;">:</span>sender<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now pay attention to the &#8220;loadNextViewSegue&#8221; part. Basically I found that 2 views inside the storyboard can be connected with a segue directly. Ctrl+click the first one and drag to the next one. These kinds of segues do require an identifier. The identifier can be easily set in the Attributes Inspector with the particular segue selected. I called mine loadNextViewSegue.</p>
<p>Going back to the previous segue isn&#8217;t as easy as I thought it would be. About this in one of the future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yacana.ro/objective-c-navigating-between-views-with-dynamically-generated-buttons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objective C: Instantiating an UIButton through a Class Method</title>
		<link>http://www.yacana.ro/objective-c-instantiating-an-uibutton-through-a-class-method/</link>
		<comments>http://www.yacana.ro/objective-c-instantiating-an-uibutton-through-a-class-method/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 00:05:52 +0000</pubDate>
		<dc:creator>octavian</dc:creator>
				<category><![CDATA[Objective-c]]></category>

		<guid isPermaLink="false">http://www.yacana.ro/?p=17</guid>
		<description><![CDATA[It wasn&#8217;t too long after starting to work with Classes in Objective C that I started to wonder how could I dynamically instantiate an UIButton, UIView ( or any other UI element for that matter ) on the Main view. I am sure this is pretty trivial for an experienced Objective C developer but it&#8217;s not that [...]]]></description>
			<content:encoded><![CDATA[<p>It wasn&#8217;t too long after starting to work with Classes in Objective C that I started to wonder how could I dynamically instantiate an UIButton, UIView ( or any other UI element for that matter ) on the Main view. I am sure this is pretty trivial for an experienced Objective C developer but it&#8217;s not that easy to figure out as a n00b.</p>
<p>In first place if you ever read anything about Objective C you have probably noticed that some methods are declared with a &#8211; and others are declared with a +:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> instanceMethod;<br />
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> classMethod;</div></td></tr></tbody></table></div>
<p>You&#8217;d call these in different ways:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MyClass <span style="color: #002200;">*</span>newInst <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MyClass alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>newInst instanceMethod<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #002200;">&#91;</span>MyClass classMethod<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>Let&#8217;s hop to our code. In this example I shall make a Class method that created a UIButton. The UIButton properties will be set through parameters.</p>
<p><strong>CreateButton.h</strong></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> makeButton<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>UIButton <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> myButton<br />
Xcoord<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> X<br />
Ycoord<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> Y<br />
withWidth<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> WIDTH<br />
withHeight<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> HEIGHT<br />
withTag<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> btTag<br />
withTitle<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> btTitle<br />
inView<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> theView;</div></td></tr></tbody></table></div>
<p><strong>CreateButton.m</strong></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> makeButton<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>UIButton <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> myButton<br />
Xcoord<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> X<br />
Ycoord<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> Y<br />
withWidth<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> WIDTH<br />
withHeight<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span> HEIGHT<br />
withTag<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> btTag<br />
withTitle<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> btTitle<br />
inView<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> theView <span style="color: #002200;">&#123;</span><br />
<br />
myButton <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeRoundedRect<span style="color: #002200;">&#93;</span>;<br />
myButton.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>X, Y, WIDTH, HEIGHT<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#91;</span>myButton setTitle<span style="color: #002200;">:</span>btTitle forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>myButton setTag<span style="color: #002200;">:</span>btTag<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>myButton setBackgroundColor<span style="color: #002200;">:</span>btColor<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>theView addSubview<span style="color: #002200;">:</span>myButton<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>At this point we have a method that creates a UIButton object and places it at specified coords on the stage on the specified view. We had to obviously include the CreateButton.h in our ViewController.h in order for this method to be visible.</p>
<p><strong>ViewController.m</strong></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span>CreateButton makeButton<span style="color: #002200;">:</span>randomButton<br />
Xcoord<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><br />
Ycoord<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><br />
withWidth<span style="color: #002200;">:</span><span style="color: #2400d9;">200</span><br />
withHeight<span style="color: #002200;">:</span><span style="color: #2400d9;">50</span><br />
withTag<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><br />
withTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Some title&quot;</span><br />
inView<span style="color: #002200;">:</span>self.view<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>At this point everything seems ready but the compiler should throw you an error &#8220;<span style="color: #ff0000;">Use of undeclared identifier randomButton</span>&#8220;. This really puzzled me as I didn&#8217;t exactly understand what the actual problem was.  But I then understood and it seemed very logical &#8211; randomButton has to be declared in ViewController.h like this:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, weak<span style="color: #002200;">&#41;</span> UIButton <span style="color: #002200;">*</span>randomButton;</div></td></tr></tbody></table></div>
<p>The result should look something like this:</p>
<p><img class="size-full wp-image-51 aligncenter" title="iPhone result" src="http://www.yacana.ro/wp-content/uploads/2012/02/class_method.png" alt="" width="396" height="744" /></p>
<p>Bare in mind &#8211; this code has been developed in XCode 4.2 with use of .storyboard and ARC ( this is why you won&#8217;t see any releases )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yacana.ro/objective-c-instantiating-an-uibutton-through-a-class-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://www.yacana.ro/hello-world/</link>
		<comments>http://www.yacana.ro/hello-world/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 21:19:02 +0000</pubDate>
		<dc:creator>octavian</dc:creator>
				<category><![CDATA[Hello World]]></category>

		<guid isPermaLink="false">http://www.yacana.ro/?p=1</guid>
		<description><![CDATA[Some things should be kept as they are even if it might seem cliché. So here it is &#8211; the Hello World! And if I am to remember the easiest &#8220;Hello World!&#8221; I ever made it must be the iPhone one. It was a simple label in a .nib. I am passionate about design and programming. [...]]]></description>
			<content:encoded><![CDATA[<p>Some things should be kept as they are even if it might seem cliché. So here it is &#8211; the Hello World!</p>
<p>And if I am to remember the easiest &#8220;Hello World!&#8221; I ever made it must be the iPhone one. It was a simple label in a .nib.</p>
<p>I am passionate about design and programming. At this point I am digging my way through iPhone development and this place, the blog, will be were I&#8217;ll drop some thoughts about what I shall encounter along the way. Of course my design work will make no exception.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yacana.ro/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

