【发布时间】:2014-11-17 21:51:50
【问题描述】:
我有以下代码,它绘制了一个圆形矩形,顶部有一个小插入符号箭头。我希望能够创建一个方法,根据我指定的内容在顶部、左侧、右侧或底部绘制箭头(我可能会传入枚举 typedef)。
这是我的代码现在生成的:
谁能帮我使这段代码更加动态/灵活,以便我完成这个?
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);
【问题讨论】:
-
您能否提供所需的图形表示...
-
@Injectios 将当前代码生成的图像添加到问题中,谢谢。
-
把三角形和主体分开画会更容易。
-
@thelaws,我很好。在这种情况下如何分离方法?
标签: ios objective-c core-graphics quartz-graphics uibezierpath