我想创建一个如下图所示的示例,而是从照片库中选择图像或使用相机拍照(如 facebook 应用程序)。此 View 是内置 View 还是我需要创建自定义 View ?
最佳答案
所以你想要一个 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/