问题
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.
回答1:
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:-
回答2:
Try this:
spinner.center = tableview.center;
Hope it Helps!!
回答3:
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.
回答4:
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.
回答5:
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];
来源:https://stackoverflow.com/questions/17985436/how-to-put-activityindicator-middle-of-a-tableview