How to display images of type .jpeg or .gif or .ti

2019-02-10 20:39发布

问题:

I am facing a problem while displaying the image in iphone. I used the below code but it work only for .png files.

      UIImageView* imageView=[[UIImageView alloc] initWithFrame:CGRectMake(6,10, 80, 80)];
      imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:customerListObject.customerImage]]];
      [myView addSubview:imageView];
      [imageView release];

I could not display the other types of image file, Please suggest me the solution.

Thank you, Madan Mohan

回答1:

Try using this:

imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"imagename" ofType:@"png"]];

And then replace imagename and png with your file name and type.