2015-07-10 126 views
0

我想在從url下載文件時顯示微調。它下載文件但不顯示微調。標籤也不在中心。 我怎樣才能讓它居中。微調(UIActivityIndi​​cator)不在iOS中顯示

我已經嘗試使用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]; 

請把一些光在它....

+0

那是你的viewDidLoad方法? – JSA986

回答

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]

截圖

+0

感謝利奧....它的工作原理......但我怎樣才能使它中心....它不在中心既不iphone4s也不在iphone6 ..... – Anjali

+0

你必須設置'containsView'的中心到'self.view.center' – Leo

+0

還有一個問題......我怎麼能隱藏容器以及標籤一旦下載完成......微調停止......我可以改變微調的顏色,而不是白色/黑/灰? – Anjali

1

我,我要表現出活動的指標,每次調用此方法。

- (void) showActivityIndicator{ 

    self.spinner.hidden=NO; 


    [self.spinner startAnimating]; 

    [self.view bringSubviewToFront:self.spinner]; 

    [self.view setNeedsDisplay]; 


    } 

在這裏,這是我的viewDidLoad方法

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

} 

並且那我如何調用該函數。

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

yes..it顯示微調器,但不在中心...... – Anjali

0

您沒有設置容器的框架。我猜你設置好的:中

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

代替

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

並把容器中心做到這一點:

container.center=self.view.center; 

在你的代碼是把容器中心本身。

+0

仍然不在中心......微調器沒有顯示 – Anjali

+0

在[self.view addSubview:container]之前調用這兩行; container.center = self.view.center; activity1ndicator.center = CGPointMake(container.frame.size.width/2,container.frame.size.height/2); – Uros19

相關問題