[image: knob.jpg]
I have this Class that I am testing out. However, the position of the ticks
is off. Seems like it needs to be moved down 1/2 way and the same to the
right. I tried doing this with a shape layer and moving that - but it
didn't change the appearance. Also, it seems like the spacing between ticks
is way off (very far apart). I am looking for a solution to this current
problem, please.
class Disc: UIView {
// Defaults.
private var myOuterRadius: CGFloat = 100.0
private var myInnerRadius: CGFloat = 90.0
private var myNumberOfTicks: Int = 5
override func draw(_ rect: CGRect)
{
let strokeColor = UIColor.black
let tickPath = UIBezierPath()
for i in 0..<myNumberOfTicks {
let angle = CGFloat(i) * CGFloat(2 * M_PI) /
CGFloat(myNumberOfTicks)
let inner = CGPoint(x: myInnerRadius * cos(angle), y:
myInnerRadius * sin(angle))
let outer = CGPoint(x: myOuterRadius * cos(angle), y:
myOuterRadius * sin(angle))
print(angle, inner, outer)
tickPath.move(to: inner)
tickPath.addLine(to: outer)
}
tickPath.close()
tickPath.lineCapStyle = .round
strokeColor.setStroke()
tickPath.lineWidth = 2
tickPath.stroke()
}
init(width: CGFloat, numTicks: Int)
{
super.init(frame: CGRect(x: 0, y: 0, width: width, height: width))
myOuterRadius = width / 2
myInnerRadius = (width / 2) - 10
myNumberOfTicks = numTicks
self.backgroundColor = UIColor(netHex: 0xEEEEEE)
self.layer.cornerRadius = CGFloat(width / 2)
self.layer.masksToBounds = true
}
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has
not been implemented") }
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]