简体   繁体   中英

How to Add image to uiactivityindicator view in ios objective c?

This is my code that I have written in my project. Instead of a spinner I want to show an image.

progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.backgroundColor = [UIColor redColor];

progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[self.view bringSubviewToFront:progress];

You can not do that as UIActivityIndicatorView is the system activity indicator. So if you want to do that then either you can create custom view for the same OR UIImageView supports animating several images in a loop(for, while) OR you can also add gif image for animation instead of UIActivityIndicatorView .

Put this code in your viewDidload() . BuildingIcon_ImageView is my imageview and when your image you want to load after set image hide UIActivityIndicatorView .

Code :

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
 [indicator startAnimating];
 [indicator setCenter:BuildingIcon_ImageView.center];
 [BuildingIcon_ImageView addSubview:indicator];

BuildingIcon_ImageView.image=image;
[indicator removeFromSuperview];

i have resolved my issue long back , posting lately this is my answer it may helpful for other thats why i am posting here.

by using NVActivityIndicatorView i resolved my problem .NVActivityIndicatorView we can choose number of custom designs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM