My UIView is always drawn in the same place regardless of where I have placed it in Interface Builder, if I have the following code in the draw function.
override func draw(_ rect: CGRect) {
let radius = CGFloat(min(frame.size.width, frame.size.height) / 2.1)
let angle: CGFloat = 2.0 * .pi / 360
var colorPath = ColorPath(path: UIBezierPath(), color: .clear)
center = CGPoint(x: frame.width / 2.0,
y: frame.height / 2.0)
for sector in 0..<360 {
let sector = CGFloat(sector)
colorPath.path = UIBezierPath(arcCenter: center, radius: radius,
startAngle: sector * angle,
endAngle: (sector + 1.0) * angle,
clockwise: true)
colorPath.path.addLine(to: center)
colorPath.path.close()
let color = UIColor(hue: sector / 360,
saturation: 1, brightness: 1, alpha: 1)
color.setFill()
color.setStroke()
colorPath.path.fill()
colorPath.path.stroke()
colorPath.color = color
paths.append(colorPath)
}
}
To me it looks like a bug, but maybe I'm doing something wrong.