如何根据下载完成的百分比更改图标



在iOS中,我如何根据下载完成的百分比来改变图标,让用户获得下载体验?

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    self.downloadedContentLength+=[data length];//data downloaded.
    double percent = ((double)self.downloadedContentLength/self.contentLength)*100;//percentage of data downloaded
    NSLog(@"PERCENT = %f", percent);
    if (percent<15) {//if percent is < 15 show image1
           //show image1
    }
    else if (percent<30)//if percent is < 30 show image2
    {
        //show image2
    }
}

每次点击didReceiveData时,它应该计算下载数据的百分比,并根据该百分比更改图像。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    self.downloadedContentLength+=[data length];//data downloaded.
    double percent = ((double)self.downloadedContentLength/self.contentLength)*100;//percentage of data downloaded
    UIImageView *downloadImage = [UIImageView alloc] init]; <- Create a Frame
    NSLog(@"PERCENT = %f", percent);
    if (percent<15) {//if percent is < 15 show image1
           downloadImage.image = [UIImage imageNamed:@"IMAGE_NAME"]; 
    }
    else if (percent<30)//if percent is < 30 show image2
    {
           downloadImage.image = [UIImage imageNamed:@"IMAGE_NAME"];
    }
}

最新更新