2013-09-21 25 views
0

調整的UILabel我試圖改變UILabel.frame一個按鈕,它工作正常:如何在viewDidLoad中

- (IBAction)changeSize:(id)sender 
    { 
     CGRect rec = self.labelHello.frame; 
     rec = CGRectMake(20, 20, 280, 300); 
     self.labelHello.frame = rec; 
    } 

但是,如果我在viewDidLoad使用相同的代碼沒有任何影響。

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

     CGRect rec = self.labelHello.frame; 
     rec = CGRectMake(20, 20, 280, 300); 
     self.labelHello.frame = rec; 
    } 

有人可以幫我嗎?

感謝的 斯特凡諾

+0

嘗試在viewWillAppear中:方法。 – Franck

+1

@Stefano如何通過XIB或編程在您的視圖中添加標籤?如果通過XIB,你需要在你的視圖被加載並且出現在'viewWillAppear'中或者通過編程把這個代碼寫在標籤的分配代碼下面的時候這樣做。 –

+0

不幸的是,它不適用於viewDidAppear,而是與viewDidAppear正常工作。 非常感謝! Stefano – Stefano

回答

0

試試這個代碼viewwillAppear..it將工作...

+0

不幸的是,它不適用於viewDidAppear,而是與viewDidAppear正常工作。非常感謝! – Stefano

+0

然後增加我的分數好友.. –

1

你可以dispatch_async騙:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     CGRect rec = self.labelHello.frame; 
     rec = CGRectMake(20, 20, 280, 300); 
     self.labelHello.frame = rec; 
    }); 
} 
+0

隨着dispatch_async工作正常! 非常感謝! – Stefano