Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the activity indicator in the navigation bar?

I am new to iphone development. I want to set an activity indicator in the navigation bar. I see my activity indicator below the navigation bar. My code is here

- (IBAction) gomethod : (id) sender {     xxMapSubviewcontroller = [[XxMapSubviewcontroller alloc] init];     [self.navigationController pushViewController:xxMapSubviewcontroller animated:YES];      activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];     activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);     [activityIndicator startAnimating];      [xxMapSubviewcontroller.view addSubview:activityIndicator]; } 

How can i set my activity indicator in the navigation bar? Please help me out. Thanks.

like image 409
Warrior Avatar asked Feb 18 '10 14:02

Warrior


People also ask

What is a navigation bar button?

The Navigation bar is there to help you navigate your phone. The traditional navigation buttons are the default layout and appear at the bottom of the screen. If you want a full screen design, you can change the Navigation bar's layout to Swipe gestures.


2 Answers

I add the below piece of code in the view where i wanted the activity indicator in the navigation bar.

activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator]; [self navigationItem].rightBarButtonItem = barButton; [activityIndicator startAnimating]; 
like image 140
Warrior Avatar answered Sep 22 '22 13:09

Warrior


Swift Code:

let activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) let barButton = UIBarButtonItem(customView: activityIndicator) self.navigationItem.setRightBarButton(barButton, animated: true) activityIndicator.startAnimating() 
like image 42
Mkey Avatar answered Sep 20 '22 13:09

Mkey