NSArray * arrayOfsubvIEws = [self.vIEw subvIEws];
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) lineBreakMode:UIlineBreakModeWorDWrap];CGRect renderingRect = CGRectMake(kborderInset + kmarginInset,kborderInset + kmarginInset + 350.0,pageSize.wIDth - 2*kborderInset - 2*kmarginInset,stringSize.height);[textToDraw drawInRect:renderingRect withFont:Font lineBreakMode:UIlineBreakModeWorDWrap alignment:UITextAlignmentleft];}总结
以上是内存溢出为你收集整理的objective-c – 将文本从uitextview绘制为pdf全部内容,希望文章能够帮你解决objective-c – 将文本从uitextview绘制为pdf所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)