开发者

Can draw on only half of UIView

开发者 https://www.devze.com 2022-12-30 23:01 出处:网络
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

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.conte开发者_如何学GontSize = 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.


I'm pretty sure you've got some of your variables mixed up.

You're looping i from 0 to height but then you're using i as your x parameter when creating lines, and using width as your y parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消