How to change the color of a UIBarButtonItem

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. It’s typically a button but it can be a bunch of different things. I’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’t change the colors of the buttons on it.

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’t have an image for.

I found a better solution here. 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 tintColor property that you can use to change the colors.

So what I did was take CharlyBr‘s code and put it into a UIBarButtonItem category.

+(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;
}

You can check out my example project on GitHub.

Posted in Uncategorized | Tagged , , , , | 5 Comments

Geocoding on the iPhone: Getting the latitude and longitude of an address

I just started working on a project where I need to take an address and turn it in to a latitude/longitude pair. It turns out that this is called geocoding. When I was looking at the docs for MapKit I noticed that Apple conveniently provided some geocoding functionality. Unfortunately it only offers reverse geocoding (turning lat/long into an address). So I went over to the Google Maps API site and checked out what was available there. The call I was interested in looks like this:

http://maps.googleapis.com/maps/api/geocode/json?
address=ADDRESS_GOES_HERE&sensor=TRUE_OR_FALSE

It gives you back a nice big JSON response with lots of information about the address, including the latitude and longitude. So I made a nice simple Geocoder class to get that information. Continue reading

Posted in Uncategorized | 1 Comment

Why Apple is winning and Android’s bigger market share doesn’t matter

I was reading an article on Engadget this morning about ATT sending messages to their users that are illegally tethering their iPhones. Most of the comments were anger at ATT, “How dare they prevent me from using their services illegally!” but there was one that caught my attention. It referenced the fact that because ATT was so shitty and expensive, some other wireless company was going to swoop in and steal their users by providing a more affordable, better tethering plan.

They compared it to what Android did to iOS. Some other big provider who would have done the same thing will step in and capitalize on the people’s indignation just like Android capitalized on people’s disappointment over Apple’s closed model.

Sure, lots of people hate Apple’s closed model. It’s bad for geeks. We can’t tinker with things like we can on our desktop computers. You know who doesn’t hate it? Everyone else. Apple’s model is perfect for the general consumer. They make it easy to install apps. They make it easy to put music on the phone. They basically make using an iPhone fun and easy. People don’t care about “open”. They care about shiny. Continue reading

Posted in Uncategorized | Tagged , , , , | 1 Comment

Simple imgur iPhone Uploader

Recently I’ve been toying with the idea of adding image uploading to Thoughtback. One easy way to do that is to use another image host and just post a link in the thought. I decided to try out imgur because of their Anonymous API. What it lets you do is upload images to their service, without requiring a username and password. This is great if you just want quick and easy image sharing.

To get started imgur has some good examples of how to upload in a variety of programming languages. I grabbed the iPhone example and copy and pasted it in thinking, “Well that was easy”. It turns out there was a little bit more to do.

Continue reading

Posted in Uncategorized | Tagged , , , , , | 2 Comments

How to create a custom cocoa framework

I was recently trying to rip out some code from the Thoughtback app into it’s own framework so that I could eventually open source when we decide to make our API public. I’ve used frameworks plenty of times, but I’ve never actually made my own.

I started off by just using the default Cocoa Framework project that XCode makes for you. It all seemed to work just fine, but when I tried actually using the framework in a different project, it wouldn’t load. I kept getting this error

Library not loaded: path/to/framework
 Referenced from: path/to/app/
 Reason: image not found

Continue reading

Posted in Uncategorized | Tagged , , , , | 1 Comment

Startups in Michigan?

So recently, I’ve been doing a lot of entrepreneury stuff with Thoughtback. My first exposure to the Lansing area entrepreneurial community was at Startup Weekend Lansing. At startup weekend, Thoughtback won the “Most popular” and “coolest” startup. We even got $1000 dollars. The next week, we were in the Lansing State Journal, the State News, and we were interviewed on the radio. All of this because of our little weekend project?

Would we have gotten any of this publicity had we won Startup Weekend San Francisco? No way. There are hundreds of companies in California doing things that are WAY more impressive than what we did with Thoughtback. But these companies don’t really exist in Michigan, especially in Lansing. So we got the benefit of being a big fish in a small sea. So where would I do a startup?

Continue reading

Posted in Uncategorized | Leave a comment

Learning from the Mac App Store

When I submitted my apps to the Mac App Store, I expected to get a few hundred downloads because the store was new. I thought every Mac developer on the planet was going to be submitting apps, but somehow, only about 1000 made it into the store.

Because there were so few apps, and even fewer free apps (just over 100), Toto and Thoughtback got WAY more attention than I expected them to. I wasn’t quite ready for it either. The big new feature of Toto is TotoSync, which lets you sync everything between the iPhone version and the Mac version. It’s something I’ve wanted to do since I first wrote Toto and I finally was able to finish it. I submitted both apps to the app store on the same day and Toto for Mac was approved right away, while Toto Touch has still not been approved. It’s been “In Review” for days and people are now asking “How do I sync with Toto Touch?” and all I can say is “Hold on, it’s coming”. I thought this could be a problem, but I never expected many people to actually want to use it. I can’t wait until it’s there.

The next problem is that since Toto and Thoughtback are meant to be ultra simple and unobtrusive, I made them little menu bar applets. They run up in the menu bar and are meant to stay out of your way. Unfortunately, a lot of people aren’t noticing them and they think they aren’t opening. I’m getting slammed in the reviews by people saying “This app sucks, it won’t even open.” So now I have a bunch of people that think my app sucks even though they haven’t even used it. Also, they started coming to my website for help. I hadn’t even gotten close to getting my website ready. I figured I’d do it eventually, because nobody will actually use this.

What did I learn? These are GOOD problems to have. People are actually using my stuff. Shit goes wrong. Apps don’t get approved, people don’t notice things you think they will, and there isn’t a ton you can do about it. So what am I going to do? Well, I’m going to update the apps so that when they open, the user get’s a little more feedback than a tiny brain in the corner or some ruby red slippers. I’m going to update my website. I’m gonna keep working to make sure that these people enjoy using my apps.

Posted in Uncategorized | 1 Comment

Mac App Store – Holy Crap

Today was the launch day for the Mac App Store. If you don’t know what it is, it’s basically the same as the iPhone App Store, but for OSX. A lot of developers have been looking forward to it and a lot of developers aren’t.

After what happened with the iPhone app store, I figured I shouldn’t miss out on the opening of the Mac App Store. So I paid the $100 and got a Mac developer account. I had been working on getting syncing working in my app, Toto, as well as putting some more stuff into Thoughtback. All I needed to do was get my apps submitted by New Years Eve and they would make it into the store.

Continue reading

Posted in Uncategorized | 4 Comments

Using blocks and Grand Central Dispatch for asynchronous web calls

Today at work, we were talking about building a REST framework and someone described how they made NSURLConnection behave synchronously. That seemed strange to me. Then, he told me that using Grand Central Dispatch made it easier to deal with threads than dealing with the delegate stuff in NSURLConnection.

I’ve been hearing about how great Grand Central Dispatch is for awhile so when I heard about a practical application of it, I decided to learn about it myself. A little bit of googling led me to a post at Cocoa Samurai. It seems to be a pretty good overview of GCD and blocks.

Based on some stuff I learned from there, I built a little demo app that uses GCD and blocks to make synchronous web calls asynchronous. Continue reading

Posted in Uncategorized | Tagged , , , , , | 1 Comment

Being a good Internet citizen.

Almost all the multimedia we consume today is free. Sure, there are websites that cost money, subscription cable, and satellite radio, but in general, we don’t pay for most of that stuff. So how do these services continue to operate? Ads. How do ads make them money?

Well, people pay to have their ads placed in front of people. The theory is, the more people that see your product, the more people will use it and the more money you’ll make. Hopefully, the amount of money you make because of your advertising makes you more money than what it cost to do the advertising. TV and radio ads are easy. People are forced to watch/listen to a stream and theres nothing they can do to truly avoid the ad (yeah yeah DVRs blah blah). The Internet is quite different. Most ads are just hanging out on the side of the page. You aren’t forced to pay any attention to them. So how does Internet advertising work?

Continue reading

Posted in Uncategorized | Tagged , | 1 Comment