IOS石英气泡带三角形
让石英绘制出我想要的形状时遇到一些困难。基本上我想要这样的形状:
我可以获得圆形气泡,但是当我尝试添加时三角形就出错了。这是我通常得到的:
感谢您的宝贵时间。
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect currentFrame = self.bounds;
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, self.BorderWidth);
CGContextSetStrokeColorWithColor(context, self.BorderColor.CGColor);
CGContextSetFillColorWithColor(context, self.FillColor.CGColor);
float pad = BorderWidth + 0.5f;
float width = currentFrame.size.width - BorderWidth - 0.5f;
float height = currentFrame.size.height - BorderWidth - 0.5f;
float rounding = BorderRadius - BorderWidth;
CGContextMoveToPoint(context,pad + TriangleSize.width, pad);
//top
CGContextAddArcToPoint(context,
width,
pad,
width,
height,
rounding);
//right
CGContextAddArcToPoint(context,
width,
height,
round(width / 2.0f),
height,
rounding);
//bottom
CGContextAddArcToPoint(context,
TriangleSize.width + pad,
height,
pad,
pad ,
rounding);
//left
CGContextAddArcToPoint(context,
TriangleSize.width,
pad + TriangleSize.height*3,
width,
pad,
0);
CGContextAddLineToPoint(context,-TriangleSize.width - pad,TriangleSize.height);
CGContextAddLineToPoint(context,pad + TriangleSize.width, pad + TriangleSize.height);
CGContextAddArcToPoint(context,
pad + TriangleSize.width,
pad - TriangleSize.height,
width,
height,
rounding);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
have some trouble getting quartz to draw the shape I want. Basically I am going for a shape like so:
I can get the rounded bubble, but when I try to add in the triangle it goes wrong. Here is what I normally get:
Thanks for your time.
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect currentFrame = self.bounds;
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, self.BorderWidth);
CGContextSetStrokeColorWithColor(context, self.BorderColor.CGColor);
CGContextSetFillColorWithColor(context, self.FillColor.CGColor);
float pad = BorderWidth + 0.5f;
float width = currentFrame.size.width - BorderWidth - 0.5f;
float height = currentFrame.size.height - BorderWidth - 0.5f;
float rounding = BorderRadius - BorderWidth;
CGContextMoveToPoint(context,pad + TriangleSize.width, pad);
//top
CGContextAddArcToPoint(context,
width,
pad,
width,
height,
rounding);
//right
CGContextAddArcToPoint(context,
width,
height,
round(width / 2.0f),
height,
rounding);
//bottom
CGContextAddArcToPoint(context,
TriangleSize.width + pad,
height,
pad,
pad ,
rounding);
//left
CGContextAddArcToPoint(context,
TriangleSize.width,
pad + TriangleSize.height*3,
width,
pad,
0);
CGContextAddLineToPoint(context,-TriangleSize.width - pad,TriangleSize.height);
CGContextAddLineToPoint(context,pad + TriangleSize.width, pad + TriangleSize.height);
CGContextAddArcToPoint(context,
pad + TriangleSize.width,
pad - TriangleSize.height,
width,
height,
rounding);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来我需要做的就是发布一个问题来解决这个问题。 :) 不管怎样,如果有人以后发现这个,这里是我用来让它工作的代码:
Looks like all I needed to do was post an question to figure it out. :) Anyway here is the code I used to get it working if anyone finds this later down the road: