progress bar downloading image

2019-03-21 19:08发布

问题:

In my application i want to show the size of downloading image in label.like, 5 KB of 2MB .

Progress bar is used to show the image downloading and i want to show the total size of currently downloading image as well as completed size of downloading(like,5 KB of 2 MB)

Anyone give me guidance to do this.

For this What should i do.please give me any sample code or tutorial for this.

Added Informations:

Already i'm using ASIHTTP Library .There are several delegate methods.In which method i want to give the code for finding the total size of the download image and progress of the downloding image.Please give me a code for findout the size of both (total size and downloaded size ) of an image.Please help me .stil i have no idea to find the size and which delegate method is used to support.

I'm really struggle in this.Please any one guide me to do this.

回答1:

Since you need some real code to start with, here are a few hints.

  • Drag and drop the ASIHTTPRequest package into your project.
  • Since what you want is download images from the internet, you only need to deal with one class in the ASI package, the ASIHTTPRequest class.
  • Read the ASIHTTPRequest.h file closely before you start. It has every interface you need.
  • Specifically, pay attention to these two methods, you will have to override them to get real-time download statistics.

.

- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength;
- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes;


回答2:

You can implement your own download progress system, or a simpler alternative that avoids reinventing the wheel would be to use the excellent ASIHTTPRequest library that provides you with a delegate method for getting the progress of a current download. It's also rather well documented: http://allseeing-i.com/ASIHTTPRequest/



回答3:

Here's a complete tutorial for building iPhone app downloading images from internet:

In part 2 there's the mechanics of having a progress bar, just download the sample project.

http://www.touch-code-magazine.com/update-your-iphone-app-with-new-content-part-2/