ric*_*chc 3 uibezierpath swift
我正在使用UIBezierPath arc方法创建一个弧.我想要将圆弧的两端修圆 - 请参阅附图,了解具体要求!circularRect版本中使用的cornerRadius选项不适用于arc方法.任何人都有关于如何实现这一目标的想法?提前致谢.(这与先前提出的问题不同,因为它提供了确切的要求)
let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
let radius: CGFloat = max(bounds.width, bounds.height)
let arcWidth: CGFloat = 10
let startAngle: CGFloat = 4.6 / 3 * ?
let endAngle: CGFloat = 4.4 / 3 * ?
let path = UIBezierPath(arcCenter: center, radius: radius/2 - arcWidth/2, startAngle: startAngle, endAngle: endAngle, clockwise: true)
path.lineWidth = arcWidth
// all thats needed to make the ends rounded is
path.lineCapStyle = .Round
path.stroke()
Run Code Online (Sandbox Code Playgroud)
E-R*_*die 12
实际上诀窍是lineCap属性.您可以使用以下代码.
func drawCircle(view: UIView, startingAngle: CGFloat, endAngle: CGFloat) -> CAShapeLayer {
let path = UIBezierPath(arcCenter: view.center, radius: CGFloat((view.bounds.size.height/2) - 10), startAngle: startingAngle, endAngle:endAngle, clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.CGPath
shapeLayer.strokeColor = UIColor.blackColor().CGColor
shapeLayer.lineWidth = 10.0
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.lineCap = kCALineCapRound
view.layer.addSublayer(shapeLayer)
return shapeLayer
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1674 次 |
| 最近记录: |