Syntax highlighting code in your blog posts is a great way to increase the visibility and readability of your posts. Since I have been working with Objective C a lot nowadays and hope to spit out a lot of blog posts about developing using Objective C and Cocoa Touch I went ahead and set up syntax color highlighting for the code snippets. Here's how you can do it for yourself on Google's Blogger (blogspot).
You need to install Syntax Highlighter for blogger. Syntax Highlighter comes with brushes for different languages, Objective C however is not one of them. An open source Objective C brush written by Scott Densmore is what I use. Add this brush to your Syntax Highlighter brush collection. Using this brush is similar to how you would use any Syntax Highlighter brush. Here's an example.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Converting RGBA color for use with UIColor
UIColor *colorFromRgba = [UIColor colorWithRed:23/255.0f green:45/255.0f blue:145/255.0f alpha:1];
NSLog(@"converted rgba color is: %@", colorFromRgba);
[self.window makeKeyAndVisible];
return YES;
}
Basically you include your code segments inside a pre block and set its (CSS) class to the Objective C brush. The above snippet, for example, was created with the following
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Converting RGBA color for use with UIColor
UIColor *colorFromRgba = [UIColor colorWithRed:23/255.0f green:45/255.0f blue:145/255.0f alpha:1];
NSLog(@"converted rgba color is: %@", colorFromRgba);
[self.window makeKeyAndVisible];
return YES;
}