如何创建具有可自定义按钮选项的模式对话框,就像"拍照或录像"一样 iPhone上的"选择现有"对话框?这些按钮不是普通的UIButton,我确信它们不是为每个应用程序手工制作的.
Chr*_*s R 15
听起来你想要使用UIActionSheet和UIImagePickerController的组合.此代码显示一个弹出窗口,允许用户选择拍照或选择现有照片,然后UIImagePickerController几乎完成其他所有操作:
- (IBAction)handleUploadPhotoTouch:(id)sender {
mediaPicker = [[UIImagePickerController alloc] init];
[mediaPicker setDelegate:self];
mediaPicker.allowsEditing = YES;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take photo", @"Choose Existing", nil];
[actionSheet showInView:self.view];
} else {
mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:mediaPicker animated:YES];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else if (buttonIndex == 1) {
mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:mediaPicker animated:YES];
[actionSheet release];
}
Run Code Online (Sandbox Code Playgroud)
注意:这假设您有一个成员变量"mediaPicker",它保留对UIImagePickerController的引用
| 归档时间: |
|
| 查看次数: |
3505 次 |
| 最近记录: |