<?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>farp.blog &#187; UIBarButtonItem</title>
	<atom:link href="http://fredandrandall.com/blog/tag/uibarbuttonitem/feed/" rel="self" type="application/rss+xml" />
	<link>http://fredandrandall.com/blog</link>
	<description>Bloggin&#039; about whatever</description>
	<lastBuildDate>Tue, 04 Nov 2014 07:15:30 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>How to change the color of a UIBarButtonItem</title>
		<link>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/</link>
		<comments>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 23:12:08 +0000</pubDate>
		<dc:creator><![CDATA[Randall]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[UIBarButtonItem]]></category>
		<category><![CDATA[UISegmentedControl]]></category>

		<guid isPermaLink="false">http://fredandrandall.com/blog/?p=310</guid>
		<description><![CDATA[EDIT: There is a new way to do this in iOS 5 that is much easier and nicer. If you want to support iOS 4, keep reading. A UIBarButtonItem is an item that goes on a UIToolbar or a UINavigationBar. &#8230; <a href="http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://fredandrandall.com/blog/wp-content/uploads/2011/03/UIBarButtonItemTint.png"><img class="alignleft size-medium wp-image-316" title="UIBarButtonItemTint" src="http://fredandrandall.com/blog/wp-content/uploads/2011/03/UIBarButtonItemTint-154x300.png" alt="" width="154" height="300" /></a></p>
<p><strong>EDIT: There is a <a title="How to change the color of UIBarButtonItem on iOS 5" href="http://fredandrandall.com/blog/2011/10/15/how-to-change-the-color-of-uibarbuttonitem-on-ios-5/">new way to do this</a> in iOS 5 that is much easier and nicer. If you want to support iOS 4, keep reading.</strong></p>
<p>A UIBarButtonItem is an item that goes on a UIToolbar or a UINavigationBar. It&#8217;s typically a button but it can be a bunch of different things. I&#8217;m going to talk about the button. A UIBarButtonItem button takes on the color of the bar that it is on. You can set the tint of a UIToolbar, but you can&#8217;t change the colors of the buttons on it.</p>
<p>I found lots of different solutions for this online, most involving adding a UIButton as the customView of the UIBarButtonItem and having some sort of image for the color you need. That works fine, until you need a color that you don&#8217;t have an image for.</p>
<p>I found a better solution <a href="http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem">here</a>. Basically what they figured out was that a UISegmentedControl with a style of UISegmentedControlStyleBar looks just like a UIBarButtonItem. A key difference is that UISegmentedControl has a nice <a href="http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html#//apple_ref/occ/instp/UISegmentedControl/tintColor">tintColor</a> property that you can use to change the colors.</p>
<p>So what I did was take <a href="https://github.com/CharlyBr/MrBrown-Blob">CharlyBr</a>&#8216;s code and put it into a UIBarButtonItem category.</p>
<pre class="brush: objc; title: ; notranslate">
+(UIBarButtonItem*)barButtonItemWithTint:(UIColor*)color andTitle:(NSString*)itemTitle andTarget:(id)theTarget andSelector:(SEL)selector
{
	UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease];
	button.momentary = YES;
	button.segmentedControlStyle = UISegmentedControlStyleBar;
	button.tintColor = color;
	[button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged];

	UIBarButtonItem *removeButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

	return removeButton;
}
</pre>
<p>You can check out my example project on <a href="https://github.com/blladnar/UIBarButtonItem-Tint">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
