如何将圆角添加到UIBezierPath自定义矩形?

问题描述 投票:14回答:3

我设法创建了圆角,但是第一个圆角(右下角)遇到了问题

问题:

  • 我可以在(moveToPoint)方法之前添加(addArcWithCenter)方法吗?
  • 如何摆脱矩形开始处的直线(右下角?)>
  • 这是我的自定义矩形和屏幕截图的代码:

let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 300, y: 0))
path.addArcWithCenter(CGPoint(x: 300-10, y: 50), radius: 10 , startAngle: 0 , endAngle: CGFloat(M_PI/2)  , clockwise: true) //1st rounded corner
path.addArcWithCenter(CGPoint(x: 200, y: 50), radius:10, startAngle: CGFloat(2 * M_PI / 3), endAngle:CGFloat(M_PI) , clockwise: true)// 2rd rounded corner
path.addArcWithCenter(CGPoint(x: 200, y: 10), radius:10, startAngle: CGFloat(M_PI), endAngle:CGFloat(3 * M_PI / 2), clockwise: true)// 3rd rounded corner
// little triangle at the bottom
path.addLineToPoint(CGPoint(x:240 , y:0))
path.addLineToPoint(CGPoint(x: 245, y: -10))
path.addLineToPoint(CGPoint(x:250, y: 0))
path.addArcWithCenter(CGPoint(x: 290, y: 10), radius: 10, startAngle: CGFloat(3 * M_PI / 2), endAngle: CGFloat(2 * M_PI ), clockwise: true)
path.closePath()

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9oUVNCUC5wbmcifQ==” alt =“在此处输入图像描述”>

我设法创建了圆角,但是第一个圆角(右下角)遇到了问题:我可以在(moveToPoint)方法之前添加(addArcWithCenter)方法吗?如何...

ios swift uibezierpath
3个回答
18
投票

9
投票

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.