Getting Photos Into the iOS Simulator

Here is a little tip a picked up over here. I am building an app that uses the UIImagePickerController. However, I was getting annoyed because it was a little difficult to test it in the simulator because there are no photos in the simulator's photo library. So here is what I did.

  1. Fire-up the iPhone simulator and then run the Safari web browser.
  2. On your computer, open the folder that contains the photo(s) you want to put into the Simulator.
  3. Drag an image from the folder and drop it onto the Safari browser window open in the Simulator.
  4. The image will then appear in Simulator's web browser.
  5. Click and hold on the image and you will see a "Save Image" dialog box appear. Click to save.
  6. Close Safari and go to Photos on the Simulator. You should now see your photo in there.

This worked out great as I can now perform basic image selection routines from within the Simulator using real-world example content.

Using Custom Fonts in iOS - Part 1

I am working on a project that requires a specific font for several of the UILabel elements. At first, I thought I was going to have to use CoreText but it actually is much, much easier to implement. This assumes you have the physical font file. (.ttf font file), and you have added it to your project. At this point you just need to access it from within your app.

First, in XCode locate the application .plist file. Usually called, [YOUR_APP_NAME]-Info.plist. (I rename many of the groups in my applications so your mileage may vary a bit.) Once you locate the file, add a new row of key: "Fonts provided by application". XCode will create the first key/value pair for you. Here is a screenshot of my .plist file entry.


Add the name of the font file in the "value" column. Be sure to spell the name of the font file EXACTLY as it is in seen in the list of files in your project. This is NOT the name you will be referencing from within your UIFont statement. This is just so your app knows where to find the font you will be referencing.

Next, you need the name of the fontface you are going to use. For this example it is Gloucester MT Extra Condensed. Now you reference it in your app.

UILabel *myLabel;
[myLabel setText:@"Some Text"];
[myLabel setFont:[UIFont fontWithName:@"Gloucester MT Extra Condensed" size:24.0]];

Build and run your program. You should now see your interface as it was meant to be seen. With all of it's Fonty goodness. (I made that word up.) The key here is that it is REALLY important that you make sure to include any spaces, dashes or underscores in the name of the font. If it's not working for you, go back and check the filename and/or the font name you pass to your UI element.

It's A Font Family Affair

OK, now you have successfully rendered a UILabel where you had a font file with only one variant. What if you have a font file that has several variants. For example, Futura has Futura Medium, Medium Italic, Condensed Medium and a few others. How are you supposed to handle that? Well you can't. You're screwed. JUST KIDDING! Settle down. Settle down. UIFont has the method: fontNamesForFamilyName that returns all of the variants for the specified font family. 

Now, remember way back a few paragraphs ago I told you to include spaces in the UIFont name? Well when you are using fontNamesForFamilyName, you need to put in the name EXACTLY as it shown within the returned array.

So as you can see, using custom fonts is pretty easy in IOS 5. You no longer have to tell your Designer to stick it when they come up with their funky UI ideas. (You may tell em' to stick it anyway.) 

Update 3/31/2012
In Xcode, go to Summary -> Build Phases -> Copy Bundle Resources and add your font files there if they are not already appearing here after adding them to your project .plist file. If you're not seeing the custom fonts you added being applied to your UI elements, this may be the reason why.