Ios – How to programmatically add a simple default loading(progress) bar in iphone app

iosiphone

I am using http communication in My iPhone app. I want to show a progress bar while it is loading data from server. How can I do it programmatically?

I just want a default progress-bar. Nothing fancy, like in android we do ProgressDialog.show();, is there any one liner for showing progress-bar in iphone?

Best Solution

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = self.view.center;    
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

Write below code when you want to show indicator

[indicator startAnimating];

write below code when you want to hide indicator

[indicator stopAnimating];