Category Archives: Snippets

Code Snippets

Tutorial on custom structs, convenience macros, storing structs and passing them around

Let’s say your app needs a custom struct. Maybe for upper/lower bounds of some values. Let’s also assume that you – like me – don’t like the thought of abusing NSSize or NSPoint just because ‘It fits the problem’. Yes, you could store your two values in both structs, but the names would be wrong and in general: doing it would be wrong.

Continue reading

Custom gradient UILabel with an outline

UPDATE: I changed a few things in KSLabel and uploaded it to github. This post is still relevant, but a little outdated. KSLabel now supports dynamic outline and gradient colors. Be sure to read the updated blog post after reading this post.


I have run into this problem a couple of times before. My friend and designer creates a beautiful image of an interface for me and I take a look at it and immediately realize that there is text with an outline and/or gradient.

The Problem

I sigh on the inside because I know it can’t be inserted in the app as an image. The text needs to be localized and IMHO it’s not nice to localize images. I know that text outlines are the most basic thing for someone who is used to Photoshop and the like, but creating those for an iOS app can be a pain.

Continue reading

Adjusting a UIView to an appearing Keyboard

Just a quick tip I found out to make better use of space in my iPhone app. Consider the following situation: You have a Highscore View with a couple of stats of the game you just finished. Naturally you would like the user to be able to enter his nickname.

The problem

The input box is so far down in the view that it gets covered by the keyboard as soon as its activated. Now the user can enter his nickname but he can not see what he is typing. That is just not acceptable.

Continue reading

UIButtons with pseudorealistic perspective

For a little side-project I wanted buttons to look like they’re being pushed ‘inside’ the interface when active. To match the overall look of the project the first step was to create two embossed images in Photoshop. One with emboss direction ‘up’ and one with emboss direction ‘down’. Then assign these images to the relevant control states of the button. Simple enough – and already looking the way I want it to. (Hover over the image to see what I mean.)

Embossed Button Continue reading