swift - 在 Swift 中更改 UIBezierPath 的颜色

标签 swift colors rect

我试图更改 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()
}

enter image description here

最佳答案

你应该这样的代码:

 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/

相关文章:

fonts - 调整字体大小以适合矩形

java - 缺少 Android Rect set() 方法

ios - 单元测试错误抛出在 block 中

ios - UITextView _firstBaselineOffsetFromTop 断言失败

html - 图像悬停颜色变化

android - 如何在xml中设置形状的背景?

java - 在主屏幕上获取应用程序小部件的位置?

ios - 全宽图像策略

ios - 容器 View 中的数据仅传递给子 VC 一次

jquery - HTML:更改图像onclick?