Panic on American ApparelCar in Snow, Part 5Car in Snow, Part 4Car in Snow, Part 3

fill the void

Cocoa Tip: Extend NSDate

Categories are a seemless way to extend existing Cocoa classes like NSDate. In my post on relative dates, I see if two timestamps land on the same day, by zeroing out the hour/minute/second components. Recently, while working on an iPhone app, I refactored it, converting it from a transformer into a category.

@implementation NSDate (Utilities)
- (NSDate *)dateAtMidnight {
	// Initialize the calendar and flags.
	NSCalendar *calendar = [NSCalendar currentCalendar];
	unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
	NSDayCalendarUnit | NSWeekdayCalendarUnit;

	// Set date's hour/minute/second to zero.
	NSDateComponents *comps = [calendar components:unitFlags fromDate:self];
	[comps setHour:0];
	[comps setMinute:0];
	[comps setSecond:0];
	return [calendar dateFromComponents:comps];
}
@end

iPhone WordPress Theme with WPtouch

A couple months ago, I was using Safari on my iPhone when I came across a blog with an amazing iPhone theme. It had a nice UITableView feel, with badges for comment counts and even an on/off switch at the bottom. And right below that, it said, “Powered by WordPress with WPtouch”. I thought, “Man, need to get me some of that.”

WPtouch is very simple to install and instantly turned my blog into an iPhone app on Mobile Safari. Check out the Photos screenshot. It uses the flickRSS plugin to generate a Photos page. Really neat. And, it’s free!




iPhone Tip: Fading Views In and Out

Most iPhone apps have a splash screen. It’s a PNG image called Default.png that gets automatically displayed (if present) when an app starts. Apple uses the image to make an app appear to load faster than it actually does, by making the splash screen a screenshot of the initial view.

A couple days ago, I stumbled across an excellent tip for fading out Default.png using Core Animation. The original version faded the image out by expanding it and lowering its alpha value. It’s a great effect, but I preferred a more general method. The code below is for a UIViewController subclass and fades out any subview. It brings the subview to the front, reduces the alpha to zero over a half second, then sends the view to the back. I use it to fade out the splash screen after the app launches and to fade out the root table view (thereby displaying the splash screen) if the user deletes all its items.

// in UIViewController subclass

- (void)animateSubviewAway:(UIView *)subview {
       if (subview == nil) return;
       self.animatedSubview = subview;
       [self.view bringSubviewToFront:subview];

       [UIView beginAnimations:nil context:nil];
       [UIView setAnimationDuration:.5];
       [UIView setAnimationDelegate:self];
       [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
       self.animatedSubview.alpha = 0.0;
       [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
       [self.view sendSubviewToBack:self.animatedSubview];
       self.animatedSubview.alpha = 1.0;
       self.animatedSubview = nil;
}

Blog Breadcrumbs: Relevance, Recognition, and Trust

Whenever I encounter a strange error message or a similar roadblock while programming, I google for answers. This approach leads to a wide array of websites, almost all blogs. (In fact, most of this site’s traffic comes from Google, presumably from the same approach.) As soon as I get to the site, I want to quickly assess the post’s relevance and my level of trust. If the site is interesting and useful, I’ll trust it more if I come across answers on it again…if I recognize it. When I designed this blog, I tried to add these same breadcrumbs that I look for when I google: relevance, recognition, and trust.

Relevance

When I click on a Google link, I want to figure out as quickly as possible if the page is relevant. So I look around for a date, an author, tags, and a comment count.

I expect the date to be embedded in the URL, but unfortunately, WordPress’s default permalink format is arcane: http://www.bdunagan.com/?p=123. The URL format is displayed to every single visitor, and yet, all this conveys is how many times I’ve posted before this. It’s a sad default when the very next option conveys both timestamp and title: http://www.bdunagan.com/2009/11/05/sample-post/. The visitor can quickly glance at the URL and instantly know the post’s age and topic. The default permalink format is really an indication of the blog creator’s laziness.

The URL is easy. One step further is the post’s meta information. I want to know the author (for a site like TUAW), tags, number of comments, and frankly, the date again (as I might be looking at the homepage where the date isn’t in the URL). All that information gives me a better idea of whether or not the post is relevant to my goals. Including that information next to the title makes sense. However, the default WordPress theme hides this information, shown above, at the bottom of the post instead of next to the title and above the fold. Worse yet, comments follow that section, so I can’t easily page-down to the bottom of the screen, as it might be tucked away in the middle.

Recognition

The default theme for WordPress is Michael Heilemann’s Kubrick. It’s a fine theme, but far too many authors stay with it, making it difficult for new visitors to trust the site and for repeat visitors to recognize the site. (Moreover, many spam blogs use this theme as well, making sites using it more difficult to trust.) Selecting an alternate theme is ridiculously easy; just go to the admin section, click Appearance, find a theme, and click “Activate”. WordPress is nicely architected such that nothing more is required. And with the large number of free, built-in themes, selecting a relatively unique one is no problem. Many insert the post’s meta information near the title, rather than at the post’s end. Creating an identifiable site helps visitors recognize you. Going with Kubrick is just lazy.

Trust

A new visitor to this site has no idea who I am. No trust at all. The only thing going for the site is the fact that it showed up in Google as possibly relevant to the visitor’s goal. In addition to the content, I put a quick description of myself at the bottom. I put links to Twitter, LinkedIn, and Flickr. Each represents a one-click path for the visitor to find out a bit about me. No guarantee it will be interesting, but it does establish I’m a real person who writes Mac software. I want to establish a modicum of trust with the visitor. It’ll help the next time the visitor comes to the site and recognizes it.

Matt Gemmell’s blog redesign is a great example of this trust in action. I visited his site yesterday but immediately thought I’d clicked on the wrong link; the theme was completely different. Instead of the graphic-rich white-on-black theme I was accustomed to, the site was text-rich black-on-white with lots of white space. I went over to Instintive Code to see if I’d mistakenly gone to Gemmell’s other blog. Nope, no work blog. So I went to the blog’s index page and saw the title “Accessible Blog Redesign”. Ah, a redesign. Still, there was a brief period when I didn’t trust the page I landed on; it wasn’t the one I built my trust on.

To drive home the importance of breadcrumbs for trust, visit Clay Shirky’s blog. Shirky is an impressive speaker and a great writer. When I read a tweet last spring about his sharp critique on the demise of newspapers, I immediately clicked through to the blog post. But I landed on a standard WordPress site with the default Kubrick theme. Weird, seemed like a guy as aware as Shirky would do something a bit more creative. I looked back through the blog’s history. Hmm, created a month ago with only three posts so far. More weird. The blog came from Shirky’s domain, but it had no links back to the homepage. And, Shirky’s homepage didn’t have any links to the blog. At this point, I’m very skeptical about the blog. I actually googled around to make sure other authoritative people linked to the blog articles, which they did. Now, nine months on, the blog still only has six posts and no links. I still find it weird. So many missing breadcrumbs.

Iterate

Ironically, in writing this blog post, I noticed that my single posts didn’t include the number of comments up at the top like the main index does. Fixed that. And I added a nice favicon from Glyphish. Iterate, iterate, iterate.


iPhone Tip: Conditional Toolbar

For an iPhone app I’m developing, I wanted a toolbar at the bottom of the initial view, but I didn’t want it appearing in the other views. I tried simply calling myUINavigationController.hidden, but the effect was a little jarring. UINavigationController has a great wrapper for that method that includes animation: setToolbarHidden:animated:. With animation, the toolbar smoothly slides in and out when going between the initial view and the other views. I inserted the method in UIViewController’s viewWillAppear and viewWillDisappear.

// in a UIViewController subclass

- (void)viewWillAppear:(BOOL)animated {
	[self.navigationController setToolbarHidden:NO animated:YES];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
	[self.navigationController setToolbarHidden:YES animated:YES];
	[super viewWillDisappear:animated];
}

← Before After →