Using Font Macros for ConsistencyTweet
In most applications, keeping with one or two fonts is a good design choice. To this end, I often include a few simple macros to keep fonts consistent, easily change font size as well as emphasis (bold).
Below are a few macros that give you an idea how I might go about specifying two primary fonts for an app:
// For text, messages, etc #define DEFAULT_FONTSIZE 15 #define DEFAULT_FONT(s) [UIFont fontWithName:@"ArialMT" size:s] #define DEFAULT_BOLDFONT(s) [UIFont fontWithName:@"Arial-BoldMT" size:s] // For table cells #define CELL_FONTSIZE 16 #define CELL_FONT(s) [UIFont fontWithName:@"Helvetica-Oblique" size:s] #define CELL_BOLDFONT(s) [UIFont fontWithName:@"Helvetica-BoldOblique" size:s]
With these macros in defined it is easy to specify fonts based on where they are used and keep things consistent across an app:
// Assume textFieldUserName is a UITextField [textFieldUserName setFont:DEFAULT_FONT(DEFAULT_FONTSIZE)]; // For bold and larger text [someTextField setFont:DEFAULT_BOLDFONT(DEFAULT_FONTSIZE + 2)]; ... // Set cell font sizes // Assume cell is a UITableViewCell [[cell textLabel] setFont:CELL_FONT(CELL_FONTSIZE)]; // For bold and larger text [[cell textLabel] setFont:CELL_BOLDFONT(CELL_FONTSIZE + 2)];
You could also add a few additional macros for fonts that support italics or other attributes. If you have similar macros, please feel free to share in the comments section.