I'm developing an app. I haven't completed my apprenticeship of Swift 2.2/3.0 and I'm in search of some answers.
First: I am using PaintCode to generate the start of Swift code. I made a drawing with the following properties:
Code Swift:
func drawSpeedView(strokeGap strokeGap: CGFloat = 30, strokeDash: CGFloat = 4, strokePhase: CGFloat = 0, strokeWidth: CGFloat = 31, strokeStartAngle: CGFloat = 225, strokeEndAngle: CGFloat = 315) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// DashedLarge Drawing
let dashedLargeRect = CGRect(x: 14.5, y: 17.5, width: 291, height: 291)
let dashedLargePath = UIBezierPath()
dashedLargePath.addArcWithCenter(CGPoint(x: dashedLargeRect.midX, y: dashedLargeRect.midY), radius: dashedLargeRect.width / 2, startAngle: -strokeStartAngle * CGFloat(M_PI)/180, endAngle: -strokeEndAngle * CGFloat(M_PI)/180, clockwise: true)
UIColor.blackColor().setStroke()
dashedLargePath.lineWidth = strokeWidth
CGContextSaveGState(context)
CGContextSetLineDash(context, strokePhase, [strokeDash, strokeGap], 2)
dashedLargePath.stroke()
CGContextRestoreGState(context)
}
My problem:
This code is optimized for iPhone 5.
For the proportion of dotted numbers, I need to create a calculation for the value of strokeDash
for iPhone 6/6s and 6+/6s+
What I need: I have no knowledge base to mount a circumference calculation yet.
I need a calculation for replace the line:
CGContextSetLineDash(context, strokePhase, [strokeDash, strokeGap], 2)
to replace with a decimal number able to put 12/6/15 dashed around the circle, no matter the perimeter of circle.
Does anyone have a solution to my problem?
Where do I start?