我试图将文本渲染为不是矩形的形状.添加矩形路径时,以下代码有效,但添加椭圆路径时则无效.最终,我想画任何路径(L形等),有没有人对此有任何好运?
-(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context,CGAffineTransformIdentity); CGMutablePathRef path = CGPathCreateMutable(); float w = 200.0; float h = 300.0; CGRect bounds = CGRectMake(10.0,10.0,w,h); // I draw using only one of the following lines CGPathAddRect(path,NULL,bounds); // THIS LINE WILL WORK //CGPathAddEllipseInRect(path,bounds); // THIS LINE WILL CRASH IT // Initialize an attributed string. CFStringRef string = CFSTR("Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum."); CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault,0); CFAttributedStringReplaceString (attrString,CFRangeMake(0,0),string); // Create the framesetter with the attributed string. CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString); CFRelease(attrString); // Create the frame and draw it into the graphics context CTFrameRef frame = CTFramesetterCreateFrame(framesetter,path,NULL); // Flip the text CGAffineTransform flip = CGAffineTransformMake(1.0,0.0,-1.0,self.frame.size.height); CGContextConcatCTM(context,flip); CTFrameDraw(frame,context); CFRelease(framesetter); CFRelease(frame); }
任何帮助或想法将不胜感激.我很难过.
解决方法
http://lists.apple.com/archives/quartz-dev/2010/Mar/msg00049.html
问题是文档错误.该功能当前不支持非矩形路径.我希望它很快就会实施,但现在还没有.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。