I have the following code which draws a rounded rect with a small caret arrow on the top. I want to be able to create a method that either draws the arrow at the top, left, right, or bottom depending on what I specify (I'll likely pass in an enum typedef).
Here is what my code generates right now:
Can anyone help me make this code more dynamic/flexible so I can accomplish this?
CGContextBeginPath(context);
CGContextMoveToPoint(context, kBubbleBorderRadius + 0.5f, kCaretHeight + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f - (kCaretHeight * 2.0) / 2.0f) + 0.5f, kCaretHeight + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f) + 0.5f, 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f + (kCaretHeight * 2.0) / 2.0f) + 0.5f, kCaretHeight + 0.5f);
CGContextAddArcToPoint(context, currentFrame.size.width - 0.5f, kCaretHeight + 0.5f, currentFrame.size.width- 0.5f, currentFrame.size.height - 0.5f, kBubbleBorderRadius);
CGContextAddArcToPoint(context, currentFrame.size.width - 0.5f, currentFrame.size.height - 0.5f, round(currentFrame.size.width / 2.0f + (kCaretHeight * 2.0) / 2.0f) + 0.5f, currentFrame.size.height - 0.5f, kBubbleBorderRadius);
CGContextAddArcToPoint(context, 0.5f, currentFrame.size.height - 0.5f, 0.5f, kCaretHeight + 0.5f, kBubbleBorderRadius);
CGContextAddArcToPoint(context, 0.5f, kCaretHeight + 0.5f, currentFrame.size.width - 0.5f, kCaretHeight + 0.5f, kBubbleBorderRadius);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFill);
I can give you point to start from. First, I would separate rectangle and arrow:
drawing simple rectangle:
Add as subview f.e:
Then simple arrow drawing on the centre of rectangle
And finally same arrow but with different points location
You need to draw just one arrow for sure based on let's say arrow direction enum. I hope you can go further with this sample