Can draw on only half of UIView

Posted by ydlee777 on Stack Overflow See other posts from Stack Overflow or by ydlee777
Published on 2010-05-21T13:21:02Z Indexed on 2010/05/21 14:51 UTC
Read the original article Hit count: 212

Filed under:
|

Hello. I am trying to draw grid on a UIView on a UIScrollView. The width of UIView is about 1000 pixels. However, I can draw lines only about first 340 pixels of the UIView. Can anyone help me on this?

The drawGrid function is

- (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);
    }

}      

}

I am also setting up the UIScrollView and UIView as follows:

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

I appreciate any help. Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about graphics