开发者

UIImageView - Displaying an image from Directory

开发者 https://www.devze.com 2023-01-11 02:47 出处:网络
I have the following code in place: - (void)viewDidLoad { NSString *homeDirectoryPath = NSHomeDirectory();

I have the following code in place:

- (void)viewDidLoad {
    NSString *homeDirectoryPath = NSHomeDirectory();
    NSString *imagePath = [homeDirectoryPath stringByAppendingString:@"/graph.png"];
    NSLog(@"Image: %@", imagePath);

    if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath isDirectory:NULL]) 
    {
        graph = imagePath;
        //[[NSFileManager defaultManager] createDirectoryAtPath:imagePath attributes:nil];
    }

'graph' is defined as UIImageView. I'm trying to display the file in the path 'imagePath'. I know the code graph = imagePath is not correct, 开发者_StackOverflow社区as the variable 'imagePath' states it contains the path to the image.

How would I display my image located at the specific image path ?

Regards, Stephen


You'll have to create an imageview object, set it as the image view's image and release the image you created:

UIImage *graphImage = [[UIImage alloc] initWithContentsOfFile: imagePath];
graph.image = graphImage;
[graphImage release];
0

精彩评论

暂无评论...
验证码 换一张
取 消