Ben10
Ben10

Reputation: 3259

How to redraw the UIBezierpath based textview text contentsize in iphone

I draw the message bubble using UIBezierpath in uiview. I render the textview inside the bezier path. My problem is when I enter the text in textview I want to message bubble size dynamically increase but I cannot do that. how can resolve the issue.

Upvotes: 4

Views: 1619

Answers (1)

Asif Mujteba
Asif Mujteba

Reputation: 4656

You can resize the UIBezierpath relative to your UITextview frame size like this:

CGRect box = CGPathGetBoundingBox(bezierpath.CGPath)
CGFloat scaleX = textView.frame.size.width / box.frame.size.width;
CGFloat scaleY = textView.frame.size.height / box.frame.size.height;
CGAffineTransform transform = CGAffineTransformMakeScale(scaleX, scaleY);
CGPathRef intermediatePath = CGPathCreateCopyByTransformingPath(bezierpath.CGPath, &transform);
bezierPath.CGPath = intermediatePath;
CFRelease(intermediatePath);

Hope that help!

Upvotes: 2

Related Questions