2010-05-21 30 views
0

我想在UIScrollView的UIView上繪製網格。 UIView的寬度約爲1000像素。不過,我可以在UIView的前340個像素上畫線 。誰可以幫我這個事?只能在UIView的一半上繪圖

的drawGrid功能

- (void)drawRect:(CGRect)rect 
{ 
NSInteger width = 25 * 5 * 10; 
NSInteger height = (10 * 2 + 10) * 12; 
NSInteger i; 

//Get the CGContext from this view 
CGContextRef context = UIGraphicsGetCurrentContext(); 

// Draw rectangle with a blue stroke color and white fill color 
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0); 
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0); 
CGContextSetLineWidth(context, 2.0); 
CGContextAddRect(context, CGRectMake(0.0, 0.0, width, height)); 
CGContextFillPath(context); 

// Draw grid with red color 
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 

// Set the width of the pen mark 
CGContextSetLineWidth(context, 0.2); 

for (i = 0; i < height; i += 5) 
{ 

    if (i % 25 == 0) 
    { 
     CGContextSetLineWidth(context, 0.4); 

     // Draw a line 
     CGContextMoveToPoint(context, i, 0.0); 
     CGContextAddLineToPoint(context, i, width); 
     CGContextStrokePath(context); 

     CGContextSetLineWidth(context, 0.2); 
    } 
    else 
    { 
     // Draw a line 
     CGContextMoveToPoint(context, i, 0.0); 
     CGContextAddLineToPoint(context, i, width); 
     CGContextStrokePath(context);  
    } 

} 

for (i = 0; i < width; i += 5) 
{ 

    if (i % 25 == 0) 
    { 
     CGContextSetLineWidth(context, 0.4); 

     // Draw a line 
     CGContextMoveToPoint(context, 0.0, i); 
     CGContextAddLineToPoint(context, height, i); 
     CGContextStrokePath(context); 

     CGContextSetLineWidth(context, 0.2); 
    } 
    else 
    { 
     // Draw a line 
     CGContextMoveToPoint(context, 0.0, i); 
     CGContextAddLineToPoint(context, height, i); 
     CGContextStrokePath(context); 
    } 

}  

} 

我還設置了UIScrollView的UIView的和如下:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 

waveScrollView = [[WaveScrollView alloc] initWithFrame:frame]; 

CGRect waveframe = CGRectMake(0, 0, 25 * 5 * 10, (10 * 2 + 10) * 12); 

EKGWaveView *ekgWaveView = [[EKGWaveView alloc] initWithFrame:waveframe]; 

waveScrollView.contentSize = CGSizeMake(waveframe.size.width, waveframe.size.height); 
waveScrollView.maximumZoomScale = 4.0; 
waveScrollView.minimumZoomScale = 0.75; 
waveScrollView.clipsToBounds = YES; 

waveScrollView.aView = ekgWaveView; 

[waveScrollView addSubview:ekgWaveView]; 

waveScrollView.delegate = self; 

[self.view addSubview:waveScrollView]; 
} 

我感謝所有幫助。謝謝。

回答

1

我很確定你有一些變數混在一起。

你從0循環iheight但此時你創建線時,使用width爲您y參數使用i爲您x參數。