2012-01-30 72 views
1

我在一個簡單的欄中顯示了一些數據,這些數據顯示了一些數值,所有工作都正常,但是現在要爲我的Y軸構建比例,我有一些基本的東西存在一些問題,obj c「for loop」路障

I = 900

然後根據一些簡單的測試在這種情況下測試得到我的圖表與scaleMaxInt天花板值,我得到例如9個師[加零] ...

這樣做事情工作,我創建了int pp = 100

- (void) drawScaleLabels:(int)scaleMaxInt 
{ 

    //temp division for scale, NOTE WHERE TO USE 9 DIVISIONS!! 

    int scaleStep = scaleMaxInt/9; 
    NSLog(@"va ::%d", scaleStep); 

    // case scaleMax : 0 < scaleMax < 1000 
    float scaleDiv = 31.5; 

    for (int i = 0; i<9; i++) 
    { // is 8, to 9 only for testing!! 
     int pp = 100; 

     self.divScaleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(469, scaleDiv+286, 60, 14)]autorelease]; 
     self.divScaleLabel.font = [UIFont fontWithName:@"FS Albert" size:14]; 
     self.divScaleLabel.textColor = [UIColor whiteColor]; 
     self.divScaleLabel.textAlignment = UITextAlignmentRight; 
     self.divScaleLabel.text =[NSString stringWithFormat:@"$%d",scaleMaxInt-scaleStep]; 

     self.divScaleLabel.backgroundColor =[UIColor clearColor]; 
     [self.view addSubview:self.divScaleLabel]; 

     scaleDiv = scaleDiv + 31.5; 
     scaleStep = scaleStep+pp; 
    } 

} 

至極顯示值列表在我的Y軸:900,800,700,600 ... 0

,但如果我使用的int scaleStep = scaleMaxInt/9

結果它給我的名單,但與的值* 2

- (void) drawScaleLabels:(int)scaleMaxInt 
{ 
    //temp division for scale, NOTE WHERE TO USE 9 DIVISIONS!! 

    int scaleStep = scaleMaxInt/9; 

    NSLog(@"va ::%d", scaleStep); 

    // case scaleMax : 0 < scaleMax < 1000 
    float scaleDiv = 31.5; 

    for (int i = 0; i<9; i++) 
    { // is 8, to 9 only for testing!! 

     //int pp = 100; 

     self.divScaleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(469, scaleDiv+286, 60, 14)]autorelease]; 
     self.divScaleLabel.font = [UIFont fontWithName:@"FS Albert" size:14]; 
     self.divScaleLabel.textColor = [UIColor whiteColor]; 
     self.divScaleLabel.textAlignment = UITextAlignmentRight; 
     self.divScaleLabel.text =[NSString stringWithFormat:@"$%d",scaleMaxInt-scaleStep]; 

     self.divScaleLabel.backgroundColor =[UIColor clearColor]; 
     [self.view addSubview:self.divScaleLabel]; 

     scaleDiv = scaleDiv + 31.5; 
     NSLog(@"va ::%d", scaleStep); 
     scaleStep = scaleStep+scaleStep; 
    } 

} 

所以Y軸爲,900,800,700,500,100,-700 ...- 24700

林愚蠢卡住此!

我怎樣才能生成Y軸的列表?,動態值,依賴於scaleMaxInt ,不會混淆?

非常感謝!

回答

1

你在你的循環有這樣的:

scaleStep = scaleStep+scaleStep; 

這意味着你將增加一倍每個scaleStep通過循環。刪除該行。相反,設置self.divScaleLabel.text是這樣的:

self.divScaleLabel.text =[NSString stringWithFormat:@"$%d", scaleMaxInt - scaleStep * i]; 
+0

多數民衆贊成它!,謝謝,經過9個小時的編碼,我有點閉合! – MaKo 2012-01-30 06:09:41