Re: Draw an arc given 2 angles.
Re: Draw an arc given 2 angles.
- Subject: Re: Draw an arc given 2 angles.
- From: Saagar Jha <email@hidden>
- Date: Thu, 25 Jan 2018 09:57:48 -0800
Saagar Jha
> On Jan 25, 2018, at 09:47, Eric E. Dolecki <email@hidden> wrote:
>
> I've been googling without great success so far.
>
> I would like to draw a 6px thick red arc (not wedge), 0º at the top of the
> screen, and from say 60° - 110º. Assume I have to create a UIBezierPath,
> and then create a CAShapeLayer with that bezier path? Then add the shape
> layer to a UIView that I have.
>
> I'll be given the 2 angles to use via sliders - so I can update the arc
> (later). I just want to nail down an initial arc. Below doesn't work.
>
> 1. How do I get things so 0º is at the top, rotate circle 90º
> counterclockwise?
> 2. How can I get the red arc?
>
> Thanks!
>
> // Circle is a UIView with a height and width of 300
>
> let centre = CGPoint (x: circle.frame.size.width / 2, y: circle.frame.size.
> height / 2)
>
> let startAngle: CGFloat = 70.0
>
> let endAngle: CGFloat = 100
>
> let a_path = UIBezierPath()
>
> a_path.move(to: CGPoint(x: circle.frame.width / 2, y: circle.frame.height
> / 2))
It looks like you’re starting from the center of the arc. I don’t think your
arc will show up if you do this since the “radius” of it is 0.
>
> a_path.addArc(withCenter: centre, radius: 150, startAngle: CGFloat
> (startAngle).toRadians(), endAngle: CGFloat(endAngle).toRadians(),
> clockwise: true)
>
>
> // Want a red stroke on the arc, I get filled black wedge instead
>
> let redColor = UIColor.red
>
> redColor.setStroke()
>
> a_path.lineWidth = 6
>
> a_path.lineCapStyle = .round
>
> a_path.stroke()
>
>
>
> let a_shapeLayer = CAShapeLayer()
>
> a_shapeLayer.path = a_path.cgPath
>
>
> circle.layer.sublayers?.forEach { $0.removeFromSuperlayer() }
>
> circle.layer.addSublayer(a_shapeLayer)
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden