norm
This user hasn't shared any biographical information
Posts by norm
Updating iPhone apps to support Retina displays
Aug 19th
The iPhone 4′s 640×960 display is night and day better than the previous generation’s 320×480 display. Supporting both is actually pretty straightforward. The simplest thing is to do nothing: iOS 4 automagically up-sizes your image assets when running on a higher resolution display like the iPhone 4. It’ll look ok, but likely pixelated for the iPhone 4′s super sharp display.
To use higher res assets for iPhone 4, while keeping the lower res versions for earlier devices, simply add higher res images into your Xcode project with the following naming convention:
<ImageName>@2x.<filename_extension>
If you have an existing image named foobar.png that is 100×100, simply name the higher res 200×200 version as foobar@2x.png, add it to your project, and re-build. You don’t need to do anything else…when that app runs on an iPhone 4, if there is a @2x version of an image, that version will be loaded instead.
This document on the Apple Developer site summarizes it nicely & goes into more detail than I’ve covered here.
Resizing UILabel inside a UITable cell when doing a swipe delete gesture
Aug 13th
When you do a right swipe gesture on a table cell in the iPhone’s Mail app, a delete button appears and the text reflows around the button, like so:
I built a similar interface that looks and functions similarly. The only problem was that when you right swiped, the delete button would appear, but the text would not reflow. Looking at the API docs, I made sure that all the subviews were added to the UITableViewCell’s contentView. I found a post on Stack Overflow that mentioned setting the contentMode property to UIViewContentModeLeft, but that didn’t work for me.
After digging around some more, I discovered that the autoresizingMask property of UILabel defaults to UIViewAutoresizingNone. When i set autoresizingMask to UIViewAutoresizingFlexibleWidth in the two UILabels (subject & body preview), they now reflow automatically when the delete button appears.
Adding random contacts and email addresses to the iPhone simulator address book
Aug 4th
I needed some test data in my iPhone simulator’s address book to test out some functionality in the Raptr iPhone app, but adding contacts one by one would have been onerous, especially since I wanted several hundred!
Thankfully, you can programmatically add contacts to the iPhone contacts so I came up with the following snippet for a quick and dirty way to add a bunch of random contacts with random email addresses:
ABAddressBookRef addressBook = ABAddressBookCreate();
// create 200 random contacts
for (int i = 0; i < 200; i++)
{
// create an ABRecordRef
ABRecordRef record = ABPersonCreate();
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABStringPropertyType);
NSString *email = [NSString stringWithFormat:@"%i@%ifoo.com", i, i];
ABMultiValueAddValueAndLabel(multi, email, kABHomeLabel, NULL);
NSString *fname = [NSString stringWithFormat:@"Name %i", i];
NSString *lname = [NSString stringWithFormat:@"Last %i", i];
// add the first name
ABRecordSetValue(record, kABPersonFirstNameProperty, fname, NULL);
// add the last name
ABRecordSetValue(record, kABPersonLastNameProperty, lname, NULL);
// add the home email
ABRecordSetValue(record, kABPersonEmailProperty, multi, NULL);
// add the record
ABAddressBookAddRecord(addressBook, record, NULL);
}
// save the address book
ABAddressBookSave(addressBook, NULL);
// release
CFRelease(addressBook);
Put this inside -viewDidLoad or -loadView, launch the simulator and you’re set: 200 random contacts added to the simulator’s Contacts app. Make sure you remove this code snippet after you’ve run it once or you’ll keep adding random contacts. If you ever want to clear out the contacts on the simulator just go to the menu: iPhone Simulator -> Reset Content and Settings…
Downloading earlier versions of iPhone OS
Jul 30th
If you’re ever in need of downloading an earlier version on the iPhone OS, iClarified has a list of iPhone firmware files for download from Apple’s servers. This is great if say you need to downgrade your iPhone 3G from iOS 4 back to iOS 3.1.3.
Grain of sand: 0, Canon SD800 IS: 1
Dec 9th
Our trusty Canon PowerShot SD800 IS locked up the other day in the lens open position and whenever it powered up a “Lens error, restart camera” error message appeared on the LCD screen and the camera would then shut off.
Ends up that there was a single grain of sand that was stuck in between the gears that open/retract the lens. The cover is secured by a few tiny screws so it’s actually pretty easy to open up. Once I got the little bugger out from in between the gears (simply by manually turning the gears by hand), I fired up the camera again and the lens started working again!
Here are some disassembly pics, with the gears that control the opening/retracting of the lens circled in yellow.





