<?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>Rune&#039;s Blog &#187; uiimageview</title>
	<atom:link href="http://runmad.com/blog/tag/uiimageview/feed/" rel="self" type="application/rss+xml" />
	<link>http://runmad.com/blog</link>
	<description>A blog about code, graphics, UI, marketing and whatever else interests me. Follow me on Twitter: @runmad</description>
	<lastBuildDate>Sat, 28 Jan 2012 14:08:13 +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>Getting visual with UITableViews [UPDATED]</title>
		<link>http://runmad.com/blog/2009/08/getting-visual-with-uitableviews/</link>
		<comments>http://runmad.com/blog/2009/08/getting-visual-with-uitableviews/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 17:14:18 +0000</pubDate>
		<dc:creator>Rune Madsen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[uiimageview]]></category>
		<category><![CDATA[uitableview]]></category>
		<category><![CDATA[uitableviewcell]]></category>

		<guid isPermaLink="false">http://www.davesenior.com/rune/?p=1</guid>
		<description><![CDATA[UPDATED 27/8: I&#8217;ve updated the code and pushed it to bitbucket. All the drawing takes place in a separate class and only one subview is added to the cell(s). Again, if you need to add images for every single cell in a large UITableView, you should probably update the code a bit to suit your [...]]]></description>
			<content:encoded><![CDATA[<table width="100%">
<tbody>
<tr>
<td><span style="font-weight: bold; color: #000000;">UPDATED 27/8:</span></td>
</tr>
</tbody>
</table>
<p>I&#8217;ve updated the code and pushed it to bitbucket. All the drawing takes place in a separate class and only one subview is added to the cell(s). Again, if you need to add images for every single cell in a large UITableView, you should probably update the code a bit to suit your needs :)</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;">$ hg clone http<span class="sy0">:</span><span class="co2">//bitbucket.org/runmad/visual-uitableview/</span></div>
</div>
<table border="0" width="100%">
<tbody>
<tr>
<td><span style="font-weight: bold; color: #000000;">ORIGINAL:</span></td>
</tr>
</tbody>
</table>
<p>I am working on an app that lists movie releases and tapping a title will display more details about the selected release in a <span style="font-family: Monaco;">UITableView</span>. One of the details include number of discs included with the product.</p>
<p>Instead of just writing the number of discs in the <span style="font-family: Monaco;"> detailTextLabel</span>, I thought it would be nice to visualize the number of discs. Where appropriate, it&#8217;s always a nice touch to use icons/images to dispay information, instead of just using text:</p>
<p style="text-align: center;"><a href="http://runmad.com/blog/wp-content/uploads/2009/08/discCount1.png"><img class="aligncenter size-full wp-image-142" title="Visualizing disc in a UITableViewCell" src="http://runmad.com/blog/wp-content/uploads/2009/08/discCount1.png" alt="" width="360" height="61" /></a></p>
<p>There&#8217;s two things added to the cell: a <span style="font-family: Monaco;">UIImage</span> and a <span style="font-family: Monaco;">UILabel</span> with the disc amount and label number updated according to the number of discs in the product.</p>
<p>The example code can of course be used for a lot of things than just display some disc icons and a number. Since they&#8217;re subviews, it&#8217;s probably not wise to use the code as is for every single cell in a large <span style="font-family: Monaco;">UITableView</span>. Since I am just displaying the icons in one cell, I do not have any memory issues when using subviews.</p>
<p>You can use any integer for the <span style="font-family: Monaco;">discCount</span>, in the example project, I just used the row number.</p>
<p><a href="http://runmad.com/blog/wp-content/uploads/2009/08/VisualUITableViewScreenshot1.png"><img class="aligncenter size-full wp-image-144" title="Visual UITableView" src="http://runmad.com/blog/wp-content/uploads/2009/08/VisualUITableViewScreenshot1.png" alt="" width="463" height="807" /></a></p>
<p>A nice touch is the spacing for the disc and label for every disc. The more discs, the less spacing there is between the images and labels (minus one pixel). You will also notice that when there&#8217;s 10 or more discs, I simply write the disc amount in the cell&#8217;s <span style="font-family: Monaco;">detailTextLabel</span> and just add one disc image (without a number label). That makes for easier reading when there&#8217;s a large amount of discs.</p>
<p>Let me know if you use the code in your own project! I&#8217;d love to <a href="mailto:rune@runmad.com">hear from you</a> if you make any updates to the code that you&#8217;d like to share.</p>
<div style="margin:0px 0px 20px;text-align:left;color:#000000; background-color:#F1EFE6; border: 1px solid rgb(211, 209, 199); padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; ">cell.textLabel.text = <span style="color:#760f15;">@&quot;Discs&quot;</span>;<br />
<span style="color:#400080;">UIImage</span> *discIcon = [<span style="color:#400080;">UIImage</span> <span style="color:#6c0540;">imageNamed:</span><span style="color:#760f15;">@&quot;iconDisc.png&quot;</span>];<br />
<span style="color:#881350;">int</span> discCount = indexPath.row + <span style="color:#0000ff;">1</span>;<br />
<span style="color:#881350;">if</span><span style="color:#003369;"> </span>(discCount &lt; <span style="color:#0000ff;">10</span>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">for</span><span style="color:#003369;"> </span>(<span style="color:#881350;">int</span> i=<span style="color:#0000ff;">0</span>; i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">CGRect</span> frame = <span style="color:#400080;">CGRectMake</span>(<span style="color:#0000ff;">83</span> + (<span style="color:#0000ff;">17</span> &#8211; discCount) * i, <span style="color:#0000ff;">11</span>, <span style="color:#0000ff;">24</span>, <span style="color:#0000ff;">27</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">UIImageView</span> *discCellImageView = [[<span style="color:#400080;">UIImageView</span> <span style="color:#ff0000;">alloc</span>] <span style="color:#6c0540;">initWithFrame:</span>frame];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCellImageView.image = discIcon;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[cell.contentView <span style="color:#6c0540;">addSubview:</span>discCellImageView];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">int</span> discNumber = <span style="color:#0000ff;">1</span> + i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">CGRect</span> labelFrame = <span style="color:#400080;">CGRectMake</span>(<span style="color:#0000ff;">86</span> + (<span style="color:#0000ff;">17</span> &#8211; discCount) * i, <span style="color:#0000ff;">8</span>, <span style="color:#0000ff;">24</span>, <span style="color:#0000ff;">27</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">UILabel</span> *discCountLabel = [[<span style="color:#400080;">UILabel</span> <span style="color:#ff0000;">alloc</span>] <span style="color:#6c0540;">initWithFrame:</span>labelFrame];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.textColor = [<span style="color:#400080;">UIColor</span> <span style="color:#6c0540;">darkGrayColor</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.font = [<span style="color:#400080;">UIFont</span> <span style="color:#6c0540;">systemFontOfSize:</span><span style="color:#0000ff;">8</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.shadowColor = [<span style="color:#400080;">UIColor</span> <span style="color:#6c0540;">whiteColor</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.shadowOffset = <span style="color:#400080;">CGSizeMake</span>(<span style="color:#0000ff;">0</span>, <span style="color:#0000ff;">1.0</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.backgroundColor = [<span style="color:#400080;">UIColor</span> <span style="color:#6c0540;">clearColor</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discCountLabel.text = [<span style="color:#400080;">NSString</span> <span style="color:#6c0540;">stringWithFormat:</span><span style="color:#760f15;">@&quot;%d&quot;</span>, <span style="color:#6c0540;">discNumber</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[cell.contentView <span style="color:#6c0540;">addSubview:</span>discCountLabel];<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
} <span style="color:#881350;">else</span> <span style="color:#881350;">if</span><span style="color:#003369;"> </span>(discCount &gt;= <span style="color:#0000ff;">10</span>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;cell.detailTextLabel.text = [<span style="color:#400080;">NSString</span> <span style="color:#6c0540;">stringWithFormat:</span><span style="color:#760f15;">@&quot;%d&quot;</span>, <span style="color:#6c0540;">discCount</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">CGRect</span> frame = <span style="color:#400080;">CGRectMake</span>(<span style="color:#0000ff;">113</span>, <span style="color:#0000ff;">11</span>, <span style="color:#0000ff;">24</span>, <span style="color:#0000ff;">27</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">UIImageView</span> *discCellImageView = [[<span style="color:#400080;">UIImageView</span> <span style="color:#ff0000;">alloc</span>] <span style="color:#6c0540;">initWithFrame:</span>frame];<br />
&nbsp;&nbsp;&nbsp;&nbsp;discCellImageView.image = discIcon;<br />
&nbsp;&nbsp;&nbsp;&nbsp;[cell <span style="color:#6c0540;">addSubview:</span>discCellImageView];<br />
}</div>
<p>You can download the project here: <a href="http://bitbucket.org/runmad/visual-uitableview/" target="_blank">http://bitbucket.org/runmad/visual-uitableview/</a>.</p>
<p>Or in Terminal:</p>
<div style="margin:0px 0px 20px;text-align:left;color:#000000; background-color:#F1EFE6; border: 1px solid rgb(211, 209, 199); padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; ">$ hg clone <span style="color:#6c0540;">http:</span><span style="color:#236e25;">//bitbucket.org/runmad/visual-uitableview/</span></div>
<p>Thanks to <a href="http://weblog.latte.ca">Blake</a> for his input and help!</p>
]]></content:encoded>
			<wfw:commentRss>http://runmad.com/blog/2009/08/getting-visual-with-uitableviews/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

