Reputation: 108
I am jumping right into it.
I am drawing a speech bubble with a UIBezierPath
, the bubble is fine and works as I would expect. The problem is how do I add text to the speech bubble so it would stay inside the UIBezierPath
. I have zero experience with drawing text, and I'm having a hard time coming up with possible solutions.
I have tried to fit a textview inside the bubble, but the solution did not work very well, and I would like to use more of the speech bubble. With the textview I can only use the rectangle shape, i would like to fill the bubble from top down, and use the complete width in the middle.
Any help and suggestions would be much appriciated.
Upvotes: 2
Views: 1563
Reputation: 108
Ok, i finally figured out how to draw/render text on a bezierpath, it can be done by taking the CGPath, and using core text. Ive did this method.
-(void)drawText:(NSString *)text {
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(myContext);
CGContextTranslateCTM(myContext, 0.0f, self.frame.size.height);
CGContextScaleCTM(myContext, 1.0f, -1.0f);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attString); // 7-2
CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL); // 8-2
CTFrameDraw(theFrame, myContext); // 11-2
CGContextRestoreGState(myContext);
}
I followered this tutorial, witch is excelent. http://invasivecode.tumblr.com/core-text
now i only need to figure out how to calculate the size of the bezierpath to contain all the text, and figure out how to move the bezierpath and the core text together, they run on different coordinate system and is giving me all kind of problems. So if anybody has experience with this i am all ears!
Best Regards Morten
Upvotes: 3