What iOS function is this image?

Just wondering if anybody could help me out identifying and creating an iOS option such as this (http://imgur.com/QSfYavr) when a user clicks on a button, it gives the option to use a camera or choose a picture from photo library. I have researched UIIMAGEPICKER however don't think that is what I am after.

I am using latest Xcode + developing for iOS 7 also.

Thanks.

Answers


You can use the following code:

// Set these delegates in the header file
<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate>

// On Button Action

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Face for Perform Dance step"
                                              delegate:self
                                     cancelButtonTitle:@"Cancel"
                                destructiveButtonTitle:nil
                                     otherButtonTitles:@"Camera", @"Select from Library", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view];

// Action sheet delegate

#pragma mark -
#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    int i = buttonIndex;
    switch(i)
    {
        case 0:
        {
            UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
            picker.delegate = self;
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker animated:YES completion:^{}];
        }
            break;
        case 1:
        {
            UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
            picker.delegate = self;
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:^{}];
        }
        default:
            // Do Nothing.........
            break;
    }
}

At last handle camera and select from gallery actions:

#pragma mark -
#pragma - mark Selecting Image from Camera and Library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Picking Image from Camera/ Library
    [picker dismissViewControllerAnimated:YES completion:^{}];
    self.selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    if (!self.selectedImage)
    {
        return;
    }

// Adjusting Image Orientation
    NSData *data = UIImagePNGRepresentation(selectedImage);
    UIImage *tmp = [UIImage imageWithData:data];
    UIImage *fixed = [UIImage imageWithCGImage:tmp.CGImage
                                         scale:selectedImage.scale
                                   orientation:self.selectedImage.imageOrientation];
    self.selectedImage = fixed;

}

This code will work on all iOS SDKs 5.x, 6.x, 7.x. Enjoy. :)


Its UIActionSheet for iOS7, if you updating your app for iOS7 looks for all iOS versions prior to iOS7, here's one already made, you can check it, https://github.com/ianb821/IBActionSheet


Need Your Help

How to determine which C/C++ objects use most memory

visual-studio-2008 debugging mixed-mode visual-c++-2008

I have a mixed mode application (managed and native) which has a high memory footprint. I already have found out that most of the memory is allocated by native code. I am not talking about a memory...