<?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>Codec &#187; opaque</title>
	<atom:link href="http://www.trembl.org/codec/tag/opaque/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.trembl.org/codec</link>
	<description>A Personal Polylogic Code/Decode &#039;Zettelkasten&#039;</description>
	<lastBuildDate>Fri, 10 Sep 2010 09:12:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Transparent Background of Custom Drawing Class</title>
		<link>http://www.trembl.org/codec/361/</link>
		<comments>http://www.trembl.org/codec/361/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 07:38:19 +0000</pubDate>
		<dc:creator>Georg Tremmel</dc:creator>
				<category><![CDATA[Raw]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[opaque]]></category>
		<category><![CDATA[transparent]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://www.trembl.org/codec/?p=361</guid>
		<description><![CDATA[Usually common problems already have simple solution. Like that one: Problem You subclassed UIView, you want to do some custom drawing in drawRect, but no matter what you do or where you draw, the background of the view remains black. - &#40;void&#41;drawRect:&#40;CGRect&#41;rect &#123; // Drawing code CGContextRef context = UIGraphicsGetCurrentContext&#40;&#41;; CGContextSetRGBFillColor&#40;context, 0.0, 0.0, 1.0, 1.0&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Usually common problems already have simple solution. Like that one:</p>
<p><strong>Problem</strong><br />
You subclassed UIView, you want to do some custom drawing in drawRect, but no matter what you do or where you draw, the background of the view remains black.</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>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;">// Drawing code</span>
 CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
 CGContextSetRGBFillColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
 CGContextFillEllipseInRect<span style="color: #002200;">&#40;</span>context, rect<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Solution</strong><br />
In the ViewController, which call the drawing class, add</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">myDrawingClass.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;</pre></div></div>

<p>- or even nicer. In the drawing class&#8217; init function:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">self.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;</pre></div></div>

<p><del datetime="2010-01-25T07:38:22+00:00"><strong>And not like that</strong><br />
- adding &#8220;self.opaque = NO;&#8221; in the drawRect: function<br />
- CGContextClearRect(context, rect);<br />
- CGContextSetAlpha(context, 0.5f);</del></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trembl.org/codec/361/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
