ios - 如何在 objective-c 中的 UILabel 上显示 UIImage 文件路径

标签 ios objective-c uiimage uilabel uiimagepickercontroller

我是 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];
}

enter image description here

我需要在 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/

相关文章:

ios - 使用Specta和OHHTTPStubs的iOS异步单元测试永远不会失败(应该这样做!)

ios - 滑动手势被误认为是触地

iphone - App Store允许这样做吗?

ios - UIImage(contentsOfFile :) returning nil despite file existing in caches directory

iphone - UIImage 的 jpg 或 png 哪个更有效率?

ios - UITableView 无法正确地为在屏幕外重新排序的单元格设置动画

iphone - 为什么单击任何按钮时我的 UIActionSheet 都会崩溃?

ios - TableView : How to proceed after catching 'NSInternalInconsistencyException' ?

ios - 如何通过 SecureEnclave 持久存储加密数据

ios - 如何在 iOS 8 中比较两个 UIImage