我正在使用 iOS 食谱 PragProg 书中的食谱,这是我正在使用的代码的原始部分:
- (void)addActivityIndicatorView {
activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin;
CGRect aiFrame = activityIndicatorView.frame;
CGFloat originX = (self.view.bounds.size.width - aiFrame.size.width) / 2;
CGFloat originY = (self.view.bounds.size.height - aiFrame.size.height) / 2;
aiFrame.origin.x = floorl(originX);
aiFrame.origin.y = floorl(originY);
activityIndicatorView.frame = aiFrame;
[self.view addSubview:activityIndicatorView];
}
我意识到我想要这个activityindicator代码用于我的其他控件上的多个activityIndicatorViews,这些控件通过Web加载数据,所以这是我制作可重用代码的实现,它没有像上面的代码对一个视图控制器那样在控件上显示activityIndicator视图它在里面。是的,我确实为使用它的每个控件单步执行此代码,我调用 [activityIndicator startAnimating]; 对于我传递给这个函数的activityIndicator。猜猜我要问的是我应该在代码的其他地方查看哪里?
- (void)addActivityIndicatorView:(UIActivityIndicatorView *)acitivityIndicator toView:(UIView *)view {
acitivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
acitivityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin;
CGRect aiFrame = acitivityIndicator.frame;
CGFloat originX = (view.bounds.size.width - aiFrame.size.width) / 2;
CGFloat originY = (view.bounds.size.height - aiFrame.size.height) / 2;
aiFrame.origin.x = floorl(originX);
aiFrame.origin.y = floorl(originY);
acitivityIndicator.frame = aiFrame;
[view addSubview:acitivityIndicator];
}