我试图更改 UIBezierPath 的颜色,所以我从 Internet 上复制了一些可靠的代码,但出现了一个我似乎无法理解的错误。下面是代码和错误。请帮忙。
override func draw(_ rect: CGRect) {
let skullRadius = min(bounds.width, bounds.height)
let skullCenter = CGPoint(x: bounds.midX, y: bounds.midY)
let skull = UIBezierPath(arcCenter: skullCenter, radius: skullRadius, startAngle: 0.0, endAngle: CGFloat(2*M_PI), clockwise: false)
skull.lineWidth = 3
UIColor.blueColor().setFill()
skull.stroke()
}
最佳答案
你应该这样的代码:
override func draw(_ rect: CGRect) {
let skullRadius = min(bounds.width, bounds.height)
let skullCenter = CGPoint(x: bounds.midX, y: bounds.midY)
let skull = UIBezierPath(arcCenter: skullCenter, radius: skullRadius, startAngle: 0.0, endAngle: CGFloat(2*M_PI), clockwise: false)
skull.lineWidth = 3
UIColor.blue.setFill()
skull.stroke()
}
关于swift - 在 Swift 中更改 UIBezierPath 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40254669/