b2cloud

27th January 2013

Interfaces that just work (iOS)

Thoughts By 4 years ago

A few months ago when the iPhone 5 came out I was going through a project I was working on at that time to make sure everything would work fine on the new screen. I didn’t need to change any code… everything just magically worked. The people in the office seemed to think this was amazing, but there’s not much to it, you just need to make your interfaces fluid ┬áso when things chance the interface will adjust and change with it

Hard coding values

Bad, very very bad. If you find yourself putting in a value, think about it for a second. Can this value be determined at runtime? In most cases the answer will be yes. I’ve even seen people put in the dimensions of the screen into an app (this is what UIScreen is for people…). Another example I used last week was keyboard insets, these also don’t need to be hard coded.

Dynamic interfaces

When the content changes the interface usually needs to change with it. Some examples being sizes of images or the size of a block of text. NSString‘s sizeWithFont: is very handy in the case of text, allowing you to find out just how big a piece of text will be when rendered to the screen so you can position stuff directly underneath it. Take advantage of autoresizing masks and auto layout (iOS6), or if code is your thing then override UIView‘s layoutSubviews method to reposition your subviews accordingly.

Images

If an image is simple enough to render in pure code then do it. Back when the retina display came out people that drew everything in code were laughing – no new images required (except for the Default image of course). Or if it’s simple enough to 9 patch then take that route. When your interface changes for a new width or height the image will stretch and wont need a new image for each size.

Universal apps

Probably obvious, but you can determine whether your device is an iPad or iPhone at runtime:

const BOOL isiPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
Recommended Posts

Dynamic UIAlertViews and UIActionSheets (and best practices)

Post by 4 years ago

Too often I see UIAlertViews and UIActionSheets being setup poorly. When adding more than 2 buttons, I see a lot of people in the delegate method hardcoding button indexes (if you find yourself hardcoding anything,...

Connect With Us

We're trusted by some of the largest businesses and enterprises to build digital products that matter.