[英]How to add activity indicator to image load
I want to add activity indicator to image load on image view. 我想向图像视图上的图像加载添加活动指示器。 How it possible please help, Thank You 怎么可能请帮助,谢谢
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray* results = [json objectForKey:@"status"];
NSArray *imageUrlArray = [results valueForKey:@"slider_image_path"];
NSLog(@"images %@",imageUrlArray);
NSMutableArray *arrayImages = [[NSMutableArray alloc] init];
for (NSString *strImageUrl in imageUrlArray) {
[arrayImages addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strImageUrl]]]];
}
self.imageview.animationImages = arrayImages;
_imageview.animationDuration = 10;
_imageview.animationRepeatCount = 0;
[_imageview startAnimating];
}
Do like following : 喜欢以下内容:
UIActivityIndicatorView *indctr = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indctr startAnimating];
[indctr setCenter:self.imageView.center];
[self.contentView addSubview:indctr];
Use this Code 使用此代码
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
[indicator setCenter:self.imageView.center];
[self.contentView addSubview:indicator];
Remove the indicator from the superview in the block's succes method. 从块的成功方法中的超级视图中删除指示器。
[_imageView setImageWithURL:[NSURL URLWithString:anURL]
success:^(UIImage *image) {
[indicator removeFromSuperview];
}
failure:^(NSError *error) {
}];
} }
You Can use the MBProgress HUD class: https://github.com/jdg/MBProgressHUD download it and in your code set this: 您可以使用MBProgress HUD类: https : //github.com/jdg/MBProgressHUD下载它,并在您的代码中进行以下设置:
-(void)viewDidLoad{
MBProgressHUD *HUD = [[MBProgressHUD alloc]initWithView:self.view];
[self.view addSubview:HUD];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
[HUD show: YES];
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray* results = [json objectForKey:@"status"];
NSArray *imageUrlArray = [results valueForKey:@"slider_image_path"];
NSLog(@"images %@",imageUrlArray);
NSMutableArray *arrayImages = [[NSMutableArray alloc] init];
for (NSString *strImageUrl in imageUrlArray) {
[arrayImages addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strImageUrl]]]];
}
self.imageview.animationImages = arrayImages;
_imageview.animationDuration = 10;
_imageview.animationRepeatCount = 0;
[_imageview startAnimating];
[HUD hide: YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.