2013-09-22 114 views
0

我想這樣做,當點擊一個按鈕時,會出現一個標籤並最終生成動畫。我做了一個開始,但這個標籤根本沒有出現。 CGRect座標正確我正在使用3頁寬的滾動視圖。無論如何,這裏是代碼在IBAction上創建標籤

UILabel *plusSymbol = [[UILabel alloc]initWithFrame:(CGRectMake(987, 349, 330, 326))]; 
plusSymbol.text = [NSString stringWithFormat:@"+%f", applesPerClick]; 
+0

您是否將標籤添加爲子視圖? – Wain

+0

我假設不,我會怎麼做? –

回答

0

嘗試添加標籤到按鈕。

UIButton *btn; 
UILabel *label; 

[btn addSubview:label]; 
+0

超級按鈕更容易按鈕,但原理是一樣的。 – Wain

+0

好吧,你是對的,但是當你添加任何對象的時候,如果我們按照添加的順序去理想的話,它應該放在最上面。 – shahil

0

當你創建代碼,您必須添加到屏幕的視圖按鈕或任何東西:

UILabel *plusSymbol = [[UILabel alloc]initWithFrame:(CGRectMake(987, 349, 330, 326))]; 
plusSymbol.text = [NSString stringWithFormat:@"+%f", applesPerClick]; 
[self.view addSubview:plusSymbol]; 




//[yourParentView addSubview:plusSymbol]; 

如果你想添加的按鈕

[yourButton addSubview:plusSymbol]; 

但要小心,因爲框架在你的父視圖。如果你的按鈕是100 * 100,那麼你必須修改plusSymbol.frameplusSymbol.frame = CGRectMake(0, 0, 100, 100);