I'm about to make a universal Tuner app but when I try to draw an Analog meter it gets messed on different devices. Maybe it's very hardcoded.. Check this:
The labels are under the same UIView too. Check the code to draw these paths:
override func draw(_ rect: CGRect) {
let center = CGPoint(x:bounds.width/2, y: bounds.height)
var radius: CGFloat = max(bounds.width, bounds.height+50)
// Define the thickness of the arc.
let arcWidth: CGFloat = 1
let startAngle: CGFloat = π
let endAngle: CGFloat = 2 * π
var path = UIBezierPath(arcCenter: center,
radius: radius/2 - arcWidth/2,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
path.lineWidth = arcWidth
counterColor.setStroke()
path.stroke()
radius = max(bounds.width, bounds.height+70)
path = UIBezierPath(arcCenter: center,
radius: radius/2 - arcWidth/2,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
let strokeColor = UIColor.black.cgColor
roundThinLayer.path = path.cgPath
roundThinLayer.strokeColor = strokeColor
roundThinLayer.lineWidth = 16.0
roundThinLayer.fillColor = UIColor.clear.cgColor
roundThinLayer.lineDashPattern = [ 0.5, 4.55 ]
//roundThinLayer.lineDashPhase = 0.25
self.layer.addSublayer(roundThinLayer)
radius = max(bounds.width, bounds.height+90)
path = UIBezierPath(arcCenter: center,
radius: radius/2 - arcWidth/2,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
roundThickLayer.path = path.cgPath
roundThickLayer.strokeColor = strokeColor
roundThickLayer.lineWidth = 40
roundThickLayer.fillColor = UIColor.clear.cgColor
roundThickLayer.lineDashPattern = [ 1.5, 140 ]
roundThickLayer.lineDashPhase = 0.25
self.layer.addSublayer(roundThickLayer)
}
Can someone help me get these values without hardcoding? i.e. I want to make the thins/thicks dashes as in the storyboard (that's running on an iPhone 7). I want to make this app universal.
Note: The autoresizing is correctly, right?
Thanks in advance.