我正在开发以下功能的 PDF 生成功能,该功能在 iOS 6 中可以正常工作,但在 iOS7 中无法正常工作,所以请帮助我解决同样的问题。
(float) drawText:(NSString *)body currentVehical:(NSInteger)currentVehical{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 0.0, 1.0);
UIFont *font = [UIFont systemFontOfSize:14.0];
NSLog(@" FRame : \n%f\n%f",(self.pageSize.width - 2*kBorderInset-2*kMarginInset),
(self.pageSize.height - 2*kBorderInset - 2*kMarginInset));
CGSize stringSize = [body sizeWithFont:font
constrainedToSize:CGSizeMake(self.pageSize.width - 2*kBorderInset-2*kMarginInset, self.pageSize.height - 2*kBorderInset - 2*kMarginInset)
lineBreakMode:NSLineBreakByWordWrapping];
CGRect renderingRect = CGRectMake(120,10+self.yCord, self.pageSize.width - 120,stringSize.height+KExtraSpaces);
NSLog(@"PDF draw rect: %@",NSStringFromCGRect(renderingRect));
if (IS_IOS7) {
NSMutableParagraphStyle *paragraphstyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphstyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphstyle.alignment = NSTextAlignmentLeft;
NSDictionary * attributes = @{ NSFontAttributeName:font, NSParagraphStyleAttributeName: paragraphstyle };
//[body drawInRect:renderingRect withAttributes:attributes];
NSStringDrawingContext *context = [NSStringDrawingContext new];
context.minimumScaleFactor = 0.1;
NSLog(@"body :%@",body);
[body drawWithRect:renderingRect options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:context];
}else{
[body drawInRect:renderingRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];
}
return stringSize.height;
}
提前致谢。