任何人都可以帮助我什么是UIView为A4尺寸纸张的图纸的大小。用于绘图的UiView尺寸是多少?A4尺寸纸张的文件是多少?
我使用下面的大小,但我的pdfView对象像标签,图像不是我提供绘图的大小。
我创建.xib并手动绘制UILabels,图像和线然后使用标签属性我为绘图提供了框架,但它们根据.xib绘制了不同的位置我提供了与.xib(0, 0,792,1122)。
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 792, 1122), nil);
+(void)drawLabels:(NSMutableArray*)arr isData:(BOOL)isdata
{
NSArray* objects = [[NSBundle mainBundle] loadNibNamed:@"PDFView" owner:nil options:nil];
UIView* mainView = [objects objectAtIndex:0];
if (isdata)
{
for (int i=1;i<=[arr count];i++)
{
UILabel *lbl=(UILabel*)[mainView viewWithTag:i];
[self drawText:[arr objectAtIndex:i-1] inFrame:lbl.frame isData:isdata];
}
}
}
//这里是我的Draw方法
+(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect isData:(BOOL)isdata
{
int length=[textToDraw length];
CFStringRef string = (__bridge CFStringRef) textToDraw;
CFMutableAttributedStringRef currentText = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CTFontRef font = CTFontCreateWithName((CFStringRef)@"Helvetica Neue Bold", 12.0f, nil);
if (isdata)
{
font = CTFontCreateWithName((CFStringRef)@"Helvetica Neue ", 12.0f, nil);
}
CFAttributedStringReplaceString (currentText,CFRangeMake(0, 0), string);
CFAttributedStringSetAttribute(currentText,CFRangeMake(0, length),kCTFontAttributeName,font);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(frameRef);
CFRelease(framesetter);
}
//画线,我使用下面的代码
for (int j=1001;j<=1003;j++)
{
UILabel *lbl=(UILabel*)[mainView viewWithTag:j];
CGPoint lblPoint=CGPointMake(lbl.frame.origin.x, lbl.frame.origin.y);
CGPoint lblPoint2=CGPointMake(lbl.frame.origin.x+lbl.frame.size.width, lbl.frame.origin.y);
[self drawLineFromPoint:lblPoint toPoint:lblPoint2];
}
+(void)drawLineFromPoint:(CGPoint)from toPoint:(CGPoint)to
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.2, 0.3, 0.2, 0.4};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGContextMoveToPoint(context, from.x, from.y);
CGContextAddLineToPoint(context, to.x, to.y);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
}
这里是我的.xib
这里是我的.pdf文件绘制
A4纸的尺寸是595 x 842点,而不是792 x 1122. –
所有标签都是直接指定'mainView'的子视图吗? –
是感谢您的时间马丁先生。 –