0
我正在用CGContext创建一个带有四个给定点的简单正方形(点应该是一个完美的正方形)。但是,iPad应用的尺寸不是200像素x 200像素,而是由300小时制成的。我错过了什么吗?CGContext的宽度似乎超过了延伸
int beginPointX, beginPointY, gridSize, gridPadding;
gridSize = 200;
gridPadding = 10;
beginPointX = gridPadding; // padding from left border
beginPointY = gridPadding; // padding from top border
// initiate UIGraphics method
UIGraphicsBeginImageContext(self.view.frame.size);
// set context for our UIGraphics method
CGContextRef context = UIGraphicsGetCurrentContext();
// set some defaults for our CGContext
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 1.0);
CGContextBeginPath(context);
// start
// build outer box
CGRect testRect = CGRectMake(beginPointX, beginPointY, (beginPointX + gridSize), (beginPointY + gridSize));
CGContextAddRect(context, testRect);
CGContextStrokePath(context);
/*
NSLog(@"Line from %dx%d to %dx%d", beginPointX, beginPointY, beginPointX, (beginPointY + gridSize));
CGContextMoveToPoint(context, beginPointX, beginPointY);
CGContextAddLineToPoint(context, beginPointX, (beginPointY + gridSize));
CGContextStrokePath(context);
NSLog(@"Line from %dx%d to %dx%d", beginPointX, (beginPointY + gridSize), (beginPointX + gridSize), (beginPointY + gridSize));
CGContextMoveToPoint(context, beginPointX, (beginPointY + gridSize));
CGContextAddLineToPoint(context, (beginPointX + gridSize), (beginPointY + gridSize));
CGContextStrokePath(context);
NSLog(@"Line from %dx%d to %dx%d", (beginPointX + gridSize), (beginPointY + gridSize), (beginPointX + gridSize), beginPointY);
CGContextMoveToPoint(context, (beginPointX + gridSize), (beginPointY + gridSize));
CGContextAddLineToPoint(context, (beginPointX + gridSize), beginPointY);
CGContextStrokePath(context);
NSLog(@"Line from %dx%d to %dx%d", (beginPointX + gridSize), beginPointY, beginPointX, beginPointY);
CGContextMoveToPoint(context, (beginPointX + gridSize), beginPointY);
CGContextAddLineToPoint(context, beginPointX, beginPointY);
CGContextStrokePath(context);
*/
// insert set of instructions into our grid pointer
grid.image = UIGraphicsGetImageFromCurrentImageContext();
有一点需要注意的是,我正在研究一种将其方向锁定到横向(如果这有什么区别)的iPad应用程序。
这是我得到在凌晨2:30工作。谢谢! – 2010-07-05 23:48:10