Spinner(UIActivityIndi​​cator)在iOS中没有显示

时间:2015-07-10 12:09:37

标签: ios ios8 xcode6

我想在从网址下载文件时显示微调器。它下载文件但不显示微调器。标签也不是中心。 我怎样才能让它成为中心。

我已经尝试过使用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];

请注意一下......

3 个答案:

答案 0 :(得分:1)

每次我想要显示活动指示符时,我都会调用此方法。

 - (void)viewDidLoad{
        [super viewDidLoad];
       // Do any additional setup after loading the view.

       self.spinner= [[UIActivityIndicatorView alloc]       initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

       self.spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);

       [self.spinner setCenter:self.view.center]; // I do this because I'm in      landscape mode
       [self.view addSubview:self.spinner];

       self.spinner.hidesWhenStopped=YES;

}

这是我的viewDidLoad方法

        [NSThread detachNewThreadSelector:@selector(showActivityIndicator) toTarget:self withObject:nil];

这就是我如何称呼这个功能。

OpenCV Error: Assertion failed (nimages > 0 && nimages == 
(int)imagePoints1.total() && (!imgPtMat2 || nimages == 
(int)imagePoints2.total())) in collectCalibrationData, file C:\OpenCV
\sources\modules\calib3d\src\calibration.cpp, line 3164

答案 1 :(得分:1)

代码

-(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]

截图

答案 2 :(得分:0)

您没有设置容器的框架。我猜你已经下定了:

activityIndicator.frame = CGRectMake(30, 55, 225, 50);

而不是

container.frame = CGRectMake(30, 55, 225, 50);

将容器放在中心位置:

container.center=self.view.center;

在您的代码中,您将容器置于其中心。

相关问题