Subclassing UIImagePickerController?

I'm trying to modify the UI that the user is presented with when they're taking a picture. Specifically, I want to remove the "Take Picture" title bar and replace it with a custom graphic.

I'm a little lost on how to start. If anyone could share some thoughts (or even a tiny bit of code) I'd greatly appreciate it.

Thanks


-hack

Mac OS X (10.5.4)

Posted on Sep 14, 2008 3:50 PM

Reply
12 replies

Sep 14, 2008 6:01 PM in response to hack4

A picker controller is just a UIViewController. A view controller has a UIView (view). A view has subviews. I'd start by using the debugger and NSLog statements and dig into the view structure trying to find out what's in there. Once you know the components you might be able to replace or change them.

Keep in mind that whatever you do in this regard could break anytime Apple puts out an update.

Sep 14, 2008 6:42 PM in response to RickMaddy

Thanks, that helps quite a bit. We've been trying to see how the view is composed, but that's proven difficult. We can obviously get into the UIImageController.h which is quite modest. Could I trouble you to explain a little further how we'd find out where the title text "Take picture", for example, is happening?

Sep 14, 2008 7:01 PM in response to hack4

Iterate over all the subviews in the controller's view. Print the class name for each. The text could be a title for a nav bar or tool bar. Or it could just be rendered text which will make it more difficult to replace because then you will need to draw over it.

The header file may not help because most (if not all) of the subviews are not referenced in an instance variable.

Something like this in your controller:


for (UIView *view in self.view.subviews) {
NSLog(@"view is a %@", [view description]);
}


Run this in 'viewDidAppear:' or something similar.

Sep 15, 2008 8:17 AM in response to RickMaddy

Fantastic. I'm currently iterating through all (two) of the picker's subviews when I create it, and I've been able to arbitrarily add my own. Removing the UINavigationBar subview doesn't seem to be reflected in my app, though. I can remove it before I check the subviews, and it's no longer listed, but I'm still seeing it within the application, which is puzzling. (The same goes for setting hidden=YES.)

Sep 16, 2008 1:40 PM in response to drummerd_ca

I just found an easy way to do this. UIImagePickerController takes a delegate. This delegate has two protocols - UIImagePickerControllerDelegate and UINavigationControllerDelegate. I added the 'willShowViewController' delegate method to my class. This will get called just before the image picker displays.

This method gets passed a navigation controller and a view controller. You can do something like this:


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationBar *bar = navigationController.navigationBar;
UINavigationItem *top = bar.topItem;
top.prompt = @"Custom prompt on my picker";
top.title = @"Custom Picker Title";
}



Now that you have access to the navigation item you can customize all you want including setting a custom title view. This may be what Phanfare is doing.

I know this works with an image picker of type 'Saved Photos Album' because I'm doing it as of 30 minutes ago. I'm assuming it will work with the 'Camera' picker too.

Oct 1, 2008 3:39 PM in response to drummerd_ca

Hello,

After much trial and error, I finally figured out how to add my own views to the tab bar for the camera control (similar to Phanfare - see http://help.phanfare.com/index.php/PhanfareiPhoneApplication). However, I would like to remove the translucent "Take Picture" text label (which I assume is a subview of the main view). Anybody have any ideas how to hide/remove it?

Thanks.

Oct 1, 2008 7:18 PM in response to hack4

This is a nice technique. I am experiencing one quirk.

I had added a UIBarButtonItem as the leftBarButtonItem of the UINavigationItem in the album photo picker and it looks and works fine.

However, if the user clicks on an album in the picker to drill into the contents of that album, my custom left button quickly jumps up several pixels as the navigation animation wipes to the left to display the next view. It looks really bad, and I am just wondering if anyone has ideas as to why this happens, or if there might be a workaround.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Subclassing UIImagePickerController?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.