我正在尝试在Xcode7游乐场中绘制一个带有NSBezierPath的部分圆圈,并且由于答案here和一些代码here,我能够得到形状。但由于某种原因,改变笔画和填充颜色让我感到困惑。
这是我现在的游乐场代码:
import Cocoa
extension NSBezierPath {
func addArcWithCenter(center: NSPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) {
let startAngleRadian = ((startAngle) * CGFloat((180.0 / M_PI)))
let endAngleRadian = ((endAngle) * CGFloat((180.0 / M_PI)))
self.appendBezierPathWithArcWithCenter(center, radius: radius, startAngle: startAngleRadian, endAngle: endAngleRadian, clockwise: !clockwise)
}
convenience init(arcCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) {
self.init()
self.addArcWithCenter(center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)
}
}
let strokeColor = NSColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
strokeColor.setStroke()
let fillColor = NSColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
fillColor.setFill()
let circleCenter = CGPointMake(100, 100)
let circleRadius = CGFloat(80)
var decimalInput = 0.25
let start = CGFloat(3 * M_PI_2)
let end = start + CGFloat(4 * M_PI_2 * decimalInput)
let circlePath = NSBezierPath(arcCenter: circleCenter, radius: circleRadius, startAngle: start, endAngle: end, clockwise: true)
circlePath.lineWidth = 4
circlePath.stroke()
我希望这里有一个红色笔触颜色,带有绿色填充。相反,我继续得到:
我确定我在这里遗漏了一些明显的东西。