我想创建一个类似于下图的示例,但可以从“照片库”中选择图像或使用相机拍摄照片(例如facebook应用)。该视图是内置视图还是我需要创建自定义视图?

最佳答案

所以你想要一个UIActionSheet吗?

做这个:

UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"What do you want to do?"
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:@"Camera", @"Photos", nil];
    [actionSheet showInView:self.view];
    [actionSheet release];


然后在clickedButtonAtIndex中执行以下操作:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Photos"]) {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
   [self presentModalViewController:picker animated:YES];
   [picker release];
}

关于ios - 弹出 View 以选择图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11002682/

10-11 14:48