ios - Spinner(UIActivityIndi​​cator) 在 iOS 中不显示

标签 ios ios8 xcode6

我想在从 url 下载文件时显示微调器。它下载文件但不显示微调器。标签也没有居中。 我怎样才能让它居中。

我已经尝试过使用 self.view.center,但没有用。

代码

container = [[UIView alloc] init];
//container.center = self.view.center;
activityLabel = [[UILabel alloc] init];

activityLabel.text = NSLocalizedString(message, @"string1");
activityLabel.textColor = [UIColor darkGrayColor];
activityLabel.font = [UIFont boldSystemFontOfSize:8];
[container addSubview:activityLabel];
activityLabel.frame = CGRectMake(30, 55, 225, 50);

activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[container addSubview:activityIndicator];
activityIndicator.frame = CGRectMake(30, 55, 225, 50);
[self.view addSubview:container];
container.center = CGPointMake(container.frame.size.width/2, container.frame.size.height/2);
self.view.backgroundColor = [UIColor whiteColor];
[activityIndicator startAnimating];

请点亮它....

最佳答案

代码

-(void)startAnimating{
UIView *  container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
container.center = self.view.center;
container.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.4];
container.layer.cornerRadius = 10;
container.layer.masksToBounds = true;
container.tag = 134;
UILabel * activityLabel = [[UILabel alloc] init];
activityLabel.frame = CGRectMake(0, 70, 100, 30);
activityLabel.text = @"Description";
activityLabel.textColor = [UIColor darkGrayColor];
activityLabel.textAlignment = NSTextAlignmentCenter;
activityLabel.font = [UIFont boldSystemFontOfSize:10];
[container addSubview:activityLabel];


UIActivityIndicatorView *  activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = CGPointMake(container.frame.size.width/2, container.frame.size.height/2);
[container addSubview:activityIndicator];

[self.view addSubview:container];

[activityIndicator startAnimating];
}

-(void)stopAnimating{
    UIView * containView = [self.view viewWithTag:134];
    [containView removeFromSuperview];
 }

当你想开始时,调用[self startAnimating]

想停止时调用[self stopAnimating]

截图

关于ios - Spinner(UIActivityIndi​​cator) 在 iOS 中不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340431/

相关文章:

ios - 禁用 iTunes 文件共享

ios - 如何在嵌入式容器之间从一个嵌入式 View 内部切换到另一个嵌入式 View ?

ios - UIScrollView - 带有白点的滚动指示器(就像在主屏幕上一样)

ios - RegisterUserNotificationSettings 在 ios 6.1 中不起作用

iphone - 如何在 iOS 8 中关闭两个 UIViewController?

ios - Xcode 6 从 UIViewController 访问 UIApplication

ios - 如何在 Snapguide 上获得模糊的主图像颜色

ios - 删除对象并创建同名的新对象,保留引用旧对象

ios8 - 将 UISearchController 添加到非 TableView

objective-c - 对于旧项目,相机在 iOS8 beta 中不能正确旋转