Second: Display it.
Adding a pictures to the simulator
One of the first obstacles is that the simulator doesn't come with any pictures. I found an article that pointed out you could import pictures into the simulator by dragging them into the simulator and then choosing Save As in Safari. This made it easy to add some test pictures into the simulator for my program to use. It's easier than navigating to the proper directory and adding it to the files if you are just doing 1 or two images.
Wrong version
I was using the beta 4.0 XCode, and when it made a new project the Window class had an extra key. Without going into to many NDA details, when I reverted my project back to 3.1.3, it didn't work. I eventually just made a brand new nib from scratch in 3.1.3 which had all the features I needed. It was a good refresher on the fiddly details of building a NIB file.
If you get an error about an invalid key in your window check to see if the UIWindow class has a root controller outlet. If it does then your nib file was built using the wrong version of Xcode.
Simple code to select
Next I made a very simple window, just a UIImage with a button. I hooked them up to the following code. This gave me the very primitive way of selecting an image and using it. Hardly rocket science, but a good first step.
- (IBAction) selectImage:(id) sender
{
UIImagePickerController *controller = [[UIImagePickerController alloc]init];
controller.delegate=self;
controller.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
controller.allowsEditing=true;
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage*)image
editingInfo:(NSDictionary*)editingInfo{
[self.image setImage:image];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
How to set image on the lock screen of iphone and ipad programmatically using xcode?
ReplyDelete