Archive for the “Cocoa” category

UITextView with Rounded Corners and Colored Border

by John Muchow on January 26, 2011

In a previous post, Add Rounded Corners and Border to UIWebview, I wrote a few lines of code to add rounded corners and a border color to a webview. A few people have inquired if this is also possible on (…)

Read the rest of this entry »

Obfuscate / Encrypt a String (NSString)

by John Muchow on August 4, 2010

Apple Keychain Services offer a secure means to store sensitive information. Through the keychain, all the hardwork is managed for you to store and retrieve content. As powerful as the keychain services are, I was recently tinkering with some code (…)

Read the rest of this entry »

Truncate a String and Append an Ellipsis, Respecting the Font Size

by John Muchow on July 26, 2010

A number of the UI related controls will automatically truncate and append ellipsis with no effort required on your part. For example, with UILabel you can specify the linebreak mode to indicate how you would like the system to manage (…)

Read the rest of this entry »

NSNotification, UserInfo and Object Methods

by John Muchow on July 1, 2010

When working with an NSNotification object, you’ll want to familiarize yourself the userInfo dictionary, which provides access to any additional objects that may be of interest to the receiver. Understanding the object method may also be helpful if you are (…)

Read the rest of this entry »

Add Rounded Corners and Border to UIWebview

by John Muchow on June 21, 2010

Beyond simply displaying websites, UIWebview can be a nice alternative when you need to display formatted text, not to mention the option of incorporating JavaScript which presents some very interesting scripting and UI opportunities. I’ve found webviews handy for presenting (…)

Read the rest of this entry »

Formatting Numbers – NSNumberFormatter Examples

by John Muchow on June 16, 2010

The previous post on how to Get Total and Free Space on the Mounted File System is a good segue to this post, as the formatting of the output from the previous code example left a little to be desired, (…)

Read the rest of this entry »

Overriding NSObject Description Method

by John Muchow on March 29, 2010

No doubt NSLog is your friend, I use it frequently to print messages to the console during development. Actually, I use a variation of the NSLog that prints messages to the console sans date, time and object information, you can (…)

Read the rest of this entry »

Storing CGPoint, CGSize and CGRect in Collections with NSValue

by John Muchow on March 17, 2010

In an earlier post CGRect, CGSize and CGPoint Functions I demonstrated a number of geometry structures available for representing a point (CGPoint – x and y coordinates), size (CGSize – height and width) and rectangles (CGRect – combination of both). (…)

Read the rest of this entry »

Get Application Icon Name

by John Muchow on February 17, 2010

In a previous post, Get Application Name, I wrote a line of code to get the application name from the app bundle. The line of code below is a slight modification that shows how to get the name that will (…)

Read the rest of this entry »

NSRange and NSString Objects

by John Muchow on December 24, 2009

When poking around NSString methods you’ll find many references to NSRange, which is nothing more than a C structure that is helpful for describing a series of items, including a starting location and a count. For example, a range is (…)

Read the rest of this entry »

Compare NSString Objects (Updated)

by John Muchow on December 21, 2009

This tip is for those new to Objective-C and Cocoa and walks through some basics on comparing NSString objects for equality. Compare NSString objects with == NSString *str1 = @"Homebrew"; NSString *str2 = @"Homebrew";   // This compares the addresses (…)

Read the rest of this entry »

Download, Create and Display an Image from URL

by John Muchow on November 4, 2009

This tip will show the steps to download and display an image from a remote resource. This is handy if you need to add an image as a subview, yet, the image is not part of your application bundle. URL (…)

Read the rest of this entry »

Date Formatter Examples – Take 4: Setting Locale

by John Muchow on July 7, 2009

A reader recently wrote and asked how to show a date output in a different language. By default, the NSDateFormatter will use the locale set on the device, so no code specific locale changes are required if you want your (…)

Read the rest of this entry »

iPhone SDK 3 and Deprecated Method Warnings

by John Muchow on June 29, 2009

A side-effect of developing code on platforms that continue to evolve, is dealing with methods that become deprecated from one release to another. If you’ve spent anytime at all with Java, you are all too familiar with this concept. With (…)

Read the rest of this entry »

UIColor Macros

by John Muchow on June 5, 2009

Below are two macros I paste inside every new iPhone project. Besides saving a few keystrokes, they work well when using the color picker application. Let’s look at the macros first: #define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1] (…)

Read the rest of this entry »