iOS 5 By Tutorials ebook

Making UIBarButtonItems in Photoshop

Recently I was working on an app that required brightly tinted tool bars and navigation bars:

A UIToolBar with a light blue tint color

As you can see, the light blue color makes the bar button hard to see and its label hard to read. Changing the background color of the button is really easy on iOS 5 because its UIBarButtonItem also has a .tintColor property. But if you still need to support iOS 4 then you’re out of luck.

In that case, the only solution is to put a UIButton inside the UIBarButtonItem and give it a background image that looks like a regular bar button. It’s a roundabout way of doing things but it works.

Previously, I would draw these bar button-lookalike images myself in Photoshop. By setting the appropriate layer styles on a rounded rectangle vector object you can make a decent approximation of what a real bar button item looks like.

This time, however, I wanted to take advantage of the actual images that UIKit itself uses to compose the UIBarButtonItem when you change the tintColor of the underlying toolbar or navigation bar.

To pull this off, you can download UIKit Artwork Extractor. Compile the app and run it on the Simulator (or on your device). It will extract all the images that are built into the various iPhone and iPad frameworks and save them to a folder on your computer.

After you have extracted the images, go into the “Shared” subfolder and look for:

  • UITintedButtonHighlight.png
  • UITintedButtonMask.png
  • UITintedButtonShadow.png

You can combine these three images with a fill color to produce a tinted UIBarButtonItem background image, like this:

How to add the different images to produce the final bar button image

The actual layers pane should look like this:

The Layers pane in Photoshop

The “Fill color” layer is simply a rectangle filled with the tint color that you want the button to have. As you can see, both the fill layer and the “shadow” layer are clipped against the red “mask” layer. If you don’t do that, the button won’t have a transparent background in the corners.

To export the image, merge all the visible layers (but not the background!) and save the image as PNG. This gives you a 11×30 pixels stretchable image.

You can use the following category to create the fake bar button items in your code. It requires that the image named “BarButton.png” is added to your project.

@implementation UIBarButtonItem (FakeButtons)
 
- (id)initWithTitle:(NSString *)title width:(CGFloat)width target:(id)target action:(SEL)action
{
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	[button setTitle:title forState:UIControlStateNormal];
	[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
	button.titleLabel.font = [UIFont boldSystemFontOfSize:12];
	button.titleLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];
	button.titleLabel.shadowOffset = CGSizeMake(0, -1);
	button.frame = CGRectMake(0, 0, width, 30);
 
	UIImage *image = [[UIImage imageNamed:@"BarButton"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
	[button setBackgroundImage:image forState:UIControlStateNormal];
 
	return (self = [self initWithCustomView:button]);
}
 
@end

In the “Shared” folder you will also find images for the UINavigationController back button (named UITintedBackButtonXXX.png), but be advised that bar button items with a custom view won’t work on UINavigationItem’s backBarButtonItem property. You’ll have to put your custom back button on leftBarButtonItem instead.

Tip: If you also want to have Retina-sized images, run Artwork Extractor on a Retina device or on the Simulator in Retina mode. It’s very enlightening to look through the rest of the extracted artwork as well.

Get up-to-date on iOS 5 with the iOS 5 By Tutorials ebook

Now that iOS 5 is out and the NDA has been lifted, we can finally talk in public about all the new features in the SDK. And there is a lot to talk about!

Together with the other members of the RayWenderlich.com Tutorial Team I’ve been hard at work these past weeks putting together an ebook that goes in-depth on many of the new technologies in iOS 5.

I contributed four chapters on Automatic Reference Counting (ARC) and Storyboards, and the book is packed with other cool stuff as well.

Some of the topics covered: iCloud, OpenGL ES 2.0 with GLKit, Newsstand, UIKit customization, using the new integrated Twitter, Turn Based Gaming with Game Center, Core Image, and much more!

Because we had to rush a bit to get it out in time, the book is currently available as a beta version. It’s already 600 pages and there are many more goodies coming. If you get the book now, you’ll receive the new chapters as they become available.

I’m really excited about this ebook. It’s a goldmine of information and I can’t wait to read it myself! Check it out at www.raywenderlich.com.

The iOS Apprentice is available too!

Speaking of ebooks, I’m happy to announce that as of today the next two parts of my beginner course The iOS Apprentice are available as well.

This course is a series of epic-length tutorials that take you from zero to writing real apps for the iPhone and iPad. It’s aimed at complete beginners and people who have experience with other languages (PHP, Java, C#) but who are new to the platform.

If you’re confused about what a delegate or a view controller is, or if the strange syntax of Objective-C scares you, then you need to get this ebook!

You can read the first part for free when you sign up for Ray’s Monthly Newsletter at www.raywenderlich.com, so check it out and let me know what you think. If you liked the first part, you’re going to love the rest of The iOS Apprentice. :-)

The iOS Apprentice preview

Good Software

Good Software…

Is instantaneous, it doesn’t make me wait.

Remembers things for me.

Draws intelligent conclusions based on my past behavior and correctly predicts what I want to do next.

Allows me to make mistakes and experiment.

Is predictable, it should not confuse me by doing something I did not expect.

Is dependable, it does not lose or corrupt my data.

Is polite, it doesn’t interrupt me.

Gets out of my way.

Puts my needs first, not those of the computer or the developer (or publisher/brand/investor/sponsor).

Is an extension of me, not another burden to carry.

Makes my life easier, not more frustrating.

Is smart, it does not require me to hold its hand all the time.

Should shape itself to my perception of reality.

(We have a long way to go still!)

Free tutorial, The iOS Apprentice: Getting Started

It’s been a while since I wrote for this blog but I had a good excuse: I’ve been working hard on my first ebook, The iOS Apprentice: iPhone and iPad Programming for Beginners.

I get a fair amount of email from beginning programmers and they usually ask the same questions. They’ve read a book or tutorial about the basics but now they’re stuck. It’s easy enough to create a simple screen with a few buttons, to show a list of items in a table view, to use the photo picker, to download something from the internet… but how do you fit all of that together? These are also the questions I keep seeing on forums and message boards. So I decided to write an ebook with the answers.

This ebook contains five epic-length tutorials, each of which takes you from scratch to a complete, fully-functional iPhone or iPad app, with step-by-step instructions and a ton of illustrations. There’s a big difference between building a simple sample project that focuses just on a single topic, and creating a real app that has many different features — the kind of app that you actually see in the App Store. The iOS Apprentice shows you how to do the latter.

This is what Bull’s Eye looks like, the game from the first chapter:

 

The finished Bull's Eye game

You can see this game in action for yourself because as of today the first chapter of the ebook is available for free!

If you’re thinking of getting started with iOS development but you have no idea where to start, then get this ebook! No knowledge of programming is assumed, so if you’ve never written a line of code before in your life, you’re in good hands.

It is my aim that by the end of these 5 tutorials you’ll be ready to turn your own ideas into real apps. This isn’t some 20-page fluff ebook, but over 500 pages and more than 500 illustrations of hands-on practical advice.

I’m currently writing the final chapters. I expect the ebook to be done by the time iOS 5.0 comes out (early fall). Of course, the tutorials make good use of the new features from iOS 5 such as Automatic Reference Counting and Storyboards.

If this sounds like something you’d be interested in, then here’s how you can get the entire first chapter for free right now:

Go to www.raywenderlich.com and sign up for Ray’s Monthly Newsletter. Ray has an excellent site with many free iOS development tutorials, and he has agreed to sell The iOS Apprentice from his website, which makes me very happy.

After signing up for his newsletter — which is a very useful resource in its own right! — you’ll receive the download link for the first chapter (23 MB).

Enjoy the free chapter and let me know how you’re getting on! In the mean time, I have a few more pages to write… :)

 

Just Say No to Splash Screens

The client briefs that I receive often contain the requirement that “the app should display our logo when it starts”. In other words, a splash screen. Unless you’re making a game, I think adding a splash screen to your app is a bad idea, and here is why:

Splash screens make your app appear to start up slower. When the user launches an app, he expects to be able to interact with it immediately. If you show a splash screen first, he has to make a context switch from what he expected to see (the actual app) to your logo and back again when the app is done loading and its real interface finally appears.

Instead, if you do what Apple recommends in the HIG—show an empty version of your UI, without any content—then the perceived app startup time is actually shorter and users are happier as a result. Anything you can do to make your users happier is something you should do.

All iPhone and iPad apps contain a launch image, Default.png, that is shown when the app is being loaded by the operating system. Unfortunately the temptation is big to put a logo in this image. Don’t, as that is not what it’s there for.

Here is the launch image of an app I recently completed for a client. Boring, but effective.

A typical Default.png launch image
Splash screens are about you, not about the user. You probably like your logo very much and I’m sure it is pretty, but here is something you need to realize: the user doesn’t particularly care about you or your logo. You, on the other hand, should care very much about the user.

Most people just want to get on with things and if your app helps them do so, great! But if the app gets in their way, it only takes three taps to uninstall.

If your app is a novelty app designed to promote your brand, then remember that unless the app delivers some kind of value, people won’t be using it for very long and they won’t get much exposure to your message. Focus on the value, not on the brand.

Forego the splash screen and find a better way to integrate your branding in the app’s user interface. Give people a good experience to associate with your brand, rather than shoving it into their faces.

The launch image is rarely shown anymore. Now that almost everyone has OS 4 with multitasking on their iPhone, apps resume where they left off the next time they are opened. This means the load image, i.e. your splash screen, is only shown for a brief instant the very first time the app is used.

The launch image also appears if your app is re-launched after it was truly terminated, which occasionally happens when there is not enough free memory to keep all suspended apps around. Most of the time, however, when the app loads the user sees a snapshot of where he last left off.

Showing your splash screen only now and then makes for a very inconsistent experience. Putting a logo in the launch image might have worked on the slower models when there was no multitasking yet, but no more.

Don’t get too clever! If your app launches really quickly—and it should!—then the load image is only visible for a second or so, especially on the fast iPhone 4. Hardly long enough to make an impression.

To “solve” this problem, some apps use a timer that keeps the splash screen visible for a few seconds more before it fades into the main interface. How silly is that? You are not doing the user any favors by purposely slowing down the launching of the app.

Let me say it again: the app is not about you, your brand or your logo, it is about the user and the goal he wants to accomplish.

If your app is a game, then it makes sense to show a “Loading…” screen but for any other apps, do the right thing and put a blank version of your UI in the default load image.