我有iPhone的初学者任何源代码,并建议相关显示图像中我们的应用程序,并选择从画廊如何挑选从画廊图像和图像放在我们的应用
0
A
回答
2
9
您可以使用此代码
- (IBAction)addImage:(id)sender {
UIActionSheet *action = [[[UIActionSheet alloc] initWithTitle:@"Select image from" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"From library",@"From camera", nil] autorelease];
[action showInView:self.view];
}
#pragma mark - ActionSheet delegates
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *pickerView =[[UIImagePickerController alloc]init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
pickerView.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:pickerView animated:YES completion:nil];
}
}else if(buttonIndex == 1) {
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:pickerView animated:YES completion:nil];
}
}
#pragma mark - PickerDelegates
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage * img = [info valueForKey:UIImagePickerControllerEditedImage];
myImageView.image = img;
}
2
1.Add this to Info.plist to access photos library. It is a new feature in ios10.
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>
2. - (IBAction)profilePicAction:(id)sender {
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"" message:@"Change Profile image" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *takePhoto=[UIAlertAction actionWithTitle:@"Take Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:takePhoto];
UIAlertAction *choosePhoto=[UIAlertAction actionWithTitle:@"Select From Photos" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentModalViewController:pickerView animated:YES];
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:choosePhoto];
UIAlertAction *actionCancel=[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.profilePic.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
相关问题
- 1. 从棒棒糖画廊挑选图像
- 2. 调整从画廊与毕加索挑选图像
- 3. iOS图像画廊
- 4. 我们如何创建一个灯箱画廊与SQL图像
- 5. 图像视图放大与手指传播在Android像画廊图像
- 6. 如何从三星画廊挑选图片
- 7. ImageView的不显示图像从画廊
- 8. 从所选图像获取图像的确切文件大小在画廊
- 9. 如何仅从画廊中选择相机捕捉图像?
- 10. 我们如何将图像放在画布上的矩形中
- 11. 移动画廊图像
- 12. Onclick图像画廊打开
- 13. 全屏图像画廊Android
- 14. 画廊图像是从画廊的中心安卓
- 15. 只使用defaul画廊应用程序显示我的图像
- 16. 图库仅挑选图像
- 17. 响应式画廊与景观和肖像图像
- 18. 保存的图像比从图库中挑选的图像大
- 19. 来自画廊意图的Android图像
- 20. 从图库中挑选图像android 5.1
- 21. 画廊与图像和文字
- 22. 如何添加图像在我自己的活动画廊从SD卡和捕获图像
- 23. 启动画廊与图像和视频取回选定的图像/视频 - Android
- 24. 安卓:Java图像选取器从画廊在getBitmap
- 25. 如何挑选从绝对路径,而不是画廊的图片在安卓
- 26. 如何发布从我的Android应用程序中选择从画廊到Facebook墙的图像?
- 27. Android画廊在特定图像打开
- 28. 从图库中挑选图像并在图像视图中创建缩略图
- 29. 如何从画廊得到图像路径中的iOS
- 30. 如何只挑选图像文件?
URL损坏,请修复。 – 2015-07-06 08:36:19