SOLVED: Check below for the solution to my problem.
Hey SO,
I'm having trouble centering the UIActivityIndicator in the center of the view. As you can see here, it's a little farther down vertically than it should be. What I have is a UIScrollView that later adds a UIImage subview. Before the UIImage loads though, I have this UIActivityIndicator to show that the image is loading.
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView.backgroundColor = [UIColor blackColor];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.view.center;
[spinner startAnimating];
[self.view addSubview:spinner];
Any ideas on how I could get the center CGPoint and set the UIActivityIndicator there? I'm not sure why self.view.center
doesn't work.
Thanks in advance.
EDIT: I had to account for the height of the navigation bar and the tab bar. The code I had to add was :
float navigationBarHeight = [[self.navigationController navigationBar] frame].size.height;
float tabBarHeight = [[[super tabBarController] tabBar] frame].size.height;
spinner.center = CGPointMake(self.view.frame.size.width / 2.0, (self.view.frame.size.height - navigationBarHeight - tabBarHeight) / 2.0);
Activity indicator is used to present progress of some activity in the app. It can be used as a drop-in for the ActivityIndicator shipped with React Native.
import { ActivityIndicator} from 'react-native'; Here are some of the important properties available with ActivityIndicator. For animating the loading indicator.It takes boolean value true to show the indicator and false to hide it. Color to be shown for the loading indicator.
Two problems:
First, self.view.center is the center of the current view's frame on it's parent's frame. If you want the center of the current view, you want CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0);
Second, your current view does not include the navigationbar, so you're centering it on the space of the screen below the nav bar. That will also make it look lower.
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