Set progress bar for downloading NSData

前端 未结 3 516
失恋的感觉
失恋的感觉 2021-02-09 14:21
NSURL *url = [NSURL URLWithString:@\"http://i0.kym-cdn.com/entries/icons/original/000/005/545/OpoQQ.jpg?1302279173\"]; 
NSData *data = [NSData dataWithContentsOfURL:url]         


        
3条回答
  •  粉色の甜心
    2021-02-09 14:59

    You can use MBProgress Hud class for loading view. You can download only two classes from here :-https://github.com/jdg/MBProgressHUD After you write this code in that class which you want to load the data Example :In your viewDidLoad you write this

    - (void) viewDidLoad
    {
        MBProgressHud *spinner =  [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
            spinner.mode = MBProgressHUDModeCustomView;
    
            [spinner setLabelText:@"Loading....."];
    
            [spinner setLabelFont:[UIFont systemFontOfSize:15]];
    
            [spinner show:YES];
    
            [self performSelectorInBackground:@selector(getData) withObject:nil];
    }
    
    - (void) getData
    {
         NSURL *url = [NSURL URLWithString:@"http://i0.kym-cdn.com/entries/icons/original/000/005/545/OpoQQ.jpg?1302279173"]; 
    
            NSData *data = [NSData dataWithContentsOfURL:url]; 
    
            imageView.image = [[[UIImage imageWithData:data];
    
            [spinner hide:YES];
    
            [spinner removeFromSuperViewOnHide];
    }
    

提交回复
热议问题