我是 iOS 新手,我遇到了关于在 UILabel 上显示文件路径的问题。我正在为画廊拍摄图像,我想在 UILabel 上显示图像名称及其扩展名。
我的代码是这样的
按钮点击...
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
imgPanCard.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
我需要在 UILabel“No. File Chosen”上显示图像名称及其扩展名 如何执行此操作。提前致谢!
最佳答案
我只是这样修改代码
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
lblPanCard.text=[imageRep filename];
[picker dismissViewControllerAnimated:NO completion:nil];
imgPanCard.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
}
关于ios - 如何在 objective-c 中的 UILabel 上显示 UIImage 文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43116099/