我想在从 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(UIActivityIndicator) 在 iOS 中不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340431/