Add Drop Shadows to your UITableViews

You may have seen iPhone tableviews that have nice drop shadows above and below the tableviews. Apple does this on apps like Clock, and the WWDC app. Reproducing this effect isn’t obvious, but here’s how.

The World Clock app showing UITableView drop shadows

Create a tableHeaderView and tableFooterView

// Create a simple view with a red background for the topUIView*tableHeader=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,22)];tableHeader.backgroundColor=[UIColorredColor];// Create a simple view with a blue background for the bottomUIView*tableFooter=[[UIViewalloc]initWithFrame:CGRectMake(0,0,480,22)];tableFooter.backgroundColor=[UIColorblueColor];myTableView.tableHeaderView=tableHeader;[tableHeaderrelease];myTableView.tableFooterView=tableFooter;[tableFooterrelease];// Have the tableview ignore our 2 views when computing sizemyTableView.contentInset=UIEdgeInsetsMake(-22,0,-22,0);

Just drop in your shadow images instead of the red and blue views, and you’re all set.