Category Archives: UI code tips

Unresponsive UI

Here are some tips for debugging unresponsive UI elements, such as a UIButton or UISlider. These tips work for me at least 90% of the time I have this problem, which is great because there are many possible causes. Use recursiveDescription The single most useful advice here is to use the undocumented API call [UIView […]

Handling rotations in UIViewController

In this post I’ll give a few general tips for handling device rotations at the UIViewController level.  These tips are for code using iOS (formerly known as iPhone OS) 3.0 or later, which includes all iPad code. 1.  In willAnimateRotationToInterfaceOrientation:duration:, size and position the view for the new orientation. This sounds obvious and easy, but there […]

Drag and drop in 3 lines

This post introduces the PuttyView class, which is built to act like a moveable and resizable window-like object in iOS.  It contains one primary view, called the contentView, and moves and resizes that view according to where the user drags their finger. (Source code link at the bottom.) Drag and drop in 3 lines Probably […]

Hacking the responder chain

This post could have also been called “How to allow user interaction with views beneath other views,” but that title is a little too long. I’m going to assume you have at least some idea of what the responder chain is for this post. (There’s an example xcode project below for those who like to […]

Fun with layers

In this post, I’ll explain how to add a border, rounded corners, and drop shadow to any UIView using some simple CALayer properties.  I’m not a CALayer guru, but these few tricks from the layer world are particularly nice to know about. These properties are present for every UIView, since every view is actually drawn […]

Drop shadows on text

UILabel is built with a handy shadow feature, but it doesn’t always look the way you might want – in this post I’ll describe the ShadowedLabel subclass which draws nicer shadows.  (Code links below.) Default UILabel shadows This code: generates a shadow that looks like this: It’s not the end of the world, but it’s […]

iPad fonts

Below is a graphic listing all the fonts supported by default on the iPad.  It’s a rather tall graphic, so I’ll keep the rest of this short post above it. Here’s the main chunk of code used to generate these images: This is the only method you need to override in your own UIViewController in […]

UIView + position

Placing and moving your views can be a little tricky if you don’t know the details of UIView’s frame, bounds, and center properties.  This post gives a quick intro to those along with a useful category for working with them (code link below) called UIView+position. frame, bounds, and center These are the three properties of […]

The pogo stick of NSRunLoop

Quick intro to NSRunLoop NSRunLoop is the object that manages the big event loop in the sky. Imagine you’re writing your own graphical OS.  A common way to build your control flow is with a loop like this: while(!UserRequestedShutDown(userInput)) { userInput = GetUserInput(); KeyApplicationHandleUserInput(userInput); } The loop continuously gathers and reacts to the user’s actions […]