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.
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.
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];
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With