Tôi đang tạo một pdf trong ứng dụng ios, sử dụng chức năng drawpdf, trong khi gọi hàm drawtext trong lớp nsobject nó vẽ văn bản rõ ràng theo khung và chuỗi mà tôi đã chỉ định.iOS: Cách đặt phông chữ khi vẽ văn bản trong thế hệ pdf?
Mã của tôi là
+(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect
{
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// Prepare the text using a Core Text Framesetter
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}
Nhưng tôi cần phải đặt fontsize văn bản lớn hơn và táo bạo hơn.
tôi đã sử dụng
CGContextSelectFont(currentContext, "Helvetica", 20, kCGEncodingMacRoman);
và
CGContextSetFontSize (currentContext, 20);
có sự tham khảo các câu trả lời được cung cấp bởi mr.texian trong hàm trên, nhưng không có thay đổi
Tôi thấy pdf tạo ra trong uiwebview.
Tôi nhận được mã này từ lưới. Tôi không biết nơi để chỉnh sửa mã cho cài đặt phông chữ. Mọi trợ giúp sẽ được đánh giá cao.
cách thêm hai dòng mã trên vào con trỏ CFAttributtedStringRef? –