Question

I have put activity indicator

 spinner.center = CGPointMake( [UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
[self.view addSubview:spinner];

But this is not properly centered in the table view. Because table view can scroll. How can i put a spinner in the center of the screen.

Was it helpful?

Solution

try with bellow code:-

    spinner.center = CGPointMake( [UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
    yourAppdelegateClass *appDelegate = (yourAppdelegateClass*)[[UIApplication sharedApplication] delegate];
    [appDelegate.window addSubview:spinner];

Code Output is:-

enter image description here

OTHER TIPS

Try this:

spinner.center = tableview.center;

Hope it Helps!!

I think you should add your indicater(Spinner) on table view instead of sel.view. and define the area frame on the indicater.

hope this will help you.

I have another solution, because I have to put a spinner at detail view controller. Maybe it will help somebody.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.spinner.hidesWhenStopped = YES;
    [self.navigationController.view addSubview:self.spinner];
}

And for positioning:

-(void)viewDidLayoutSubviews
{  
    [super viewDidLayoutSubviews];
    [self.navigationController.view setNeedsLayout];
    [self.navigationController.view layoutIfNeeded];
    self.spinner.frame = CGRectMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2, 10, 10);
}

Spinner will be always at center of your table view at detail view controller.

Please find below code:

UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake( [UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[spinner startAnimating];
[appDelegate.window addSubview:spinner];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top