大佬教程收集整理的这篇文章主要介绍了objective-c – 将文本从uitextview绘制为pdf,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
for (int i=0; i<[arrayOfsubviews count]; i++) { if ([[arrayOfsubviews objectATindex:i]isKindOfClass:[UITextView class]]) { UITextView *texts=[arrayOfsubviews objectATindex:i]; CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)texts.font.fontName,texts.font.pointSize,null); CGColorRef color = texts.textColor.CGColor; NSDictionary *attributesDict = [NSDictionary DictionaryWithObjectsAndKeys: (__bridge id)ctFont,(id)kCTFontAttributename,color,(id)kCTForegroundColorAttributename,nil]; NSAttributedString *StringToDraw = [[NSAttributedString alloc] initWithString:texts.text attributes:attributesDict]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef) StringToDraw); CGRect rect=CGRectMake(texts.frame.origin.x,916-texts.frame.origin.y-texts.frame.size.height,texts.frame.size.width,texts.frame.size.height); CGMutablePathRef pathRef = CGPathCreateMutable(); CGPathAddRect(pathRef,NULL,rect); CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0),pathRef,null); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextTranslateCTM(context,916); CGContextScaleCTM(context,1.0,-1.0); CTFrameDraw(frameRef,context); CGContextRestoreGState(context); CGPathRelease(pathRef); } } UIGraphicsEndPDFContext();
#define kBorderInset 20.0 #define kMarginInset 10.0 - (void) drawText{ CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(currentContext,0.0,1.0); NSString *textToDraw = @"Your Text Here"; UIFont *font = [UIFont systemFontOfSize:14.0]; CGSize StringSize = [textToDraw sizeWithFont:font consTrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset-2*kMarginInset,pageSize.height - 2*kBorderInset - 2*kMarginInset) lineBrea@R_489_11076@e:UILineBrea@R_489_11076@eWordWrap]; CGRect renderingRect = CGRectMake(kBorderInset + kMarginInset,kBorderInset + kMarginInset + 350.0,pageSize.width - 2*kBorderInset - 2*kMarginInset,StringSize.height); [textToDraw drawInRect:renderingRect withFont:font lineBrea@R_489_11076@e:UILineBrea@R_489_11076@eWordWrap alignment:UITextAlignmentLeft]; }
以上是大佬教程为你收集整理的objective-c – 将文本从uitextview绘制为pdf全部内容,希望文章能够帮你解决objective-c – 将文本从uitextview绘制为pdf所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。