2012-06-29 79 views
0

我創建了一個計數動畫,現在我想創建一個包含我的標籤文本值的整數,如下所示:如果我的標籤顯示數字,那麼我的整數將等於1,所以上..我該怎麼辦呢? 這裏是我的代碼:隱藏標籤文本到整數

-(void)countup 
{ 
    count = 1; 
    MainInt += 1; 
    numbersLabel.text = [NSString stringWithFormat:@"%i", MainInt]; 
    NSLog(@"%d", count); 

} 

-(void)viewdidload 
{ 
[numbersLabel setOutlineColor:[UIColor whiteColor]]; 
[numbersLabel setGradientColor:[UIColor blackColor]]; 
numbersLabel.drawOutline = YES; 
numbersLabel.drawDoubleOutline = YES; 
numbersLabel.text = @"start"; 
//numbersLabel.font = [UIFont fontWithName:@"Ballpark" size:220]; 
numbersLabel.font = [UIFont fontWithName:@"Arial" size:220]; 


    MainInt = 1; 
    numbersTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(countup) userInfo:nil repeats:YES]; 
} 

謝謝!

+0

不能完全肯定還是你找什麼做的?您顯示的代碼已經使用計時器和計數器例程計數了,您還想要做什麼? – trumpetlicks

回答

3

如果標籤只包含數字值(或者數字值在標籤中首先出現),則可以簡單地在字符串上調用intValue

int i = label.text.intValue; 

的文檔,這是在這裏:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/intValue

+1

謝謝!我不明白我怎麼能忘記這個功能... – cnaaniomer

+2

沒問題,只是不要忘記'接受'的答案。 :) –