我有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