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];
}

ありがとう!

4

1 に答える 1

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

于 2012-06-29T12:49:58.150 に答える