gpt4 book ai didi

ios - 为什么使用 Core Graphics 绘制直线我得到 "dashed"行?

转载 作者:搜寻专家 更新时间:2023-11-01 06:20:45 25 4
gpt4 key购买 nike

我试图用下面的快速代码绘制一个图标,但我得到了“虚线”线。我刚刚使用了 moveToPointaddLineToPoint 函数。正如您在下面的图片中看到的那样,我也遇到了与其他绘图相同的图形故障。我使用 Xcode 7.2 并在 iOS 9.2.1 上运行代码。

@IBDesignable class DeleteButton: UIButton {

override func drawRect(rect: CGRect) {

UIColor.blackColor().setStroke()
let lineWidth = CGFloat(1)

// Draw empty circle
let frame = CGRect(x: rect.origin.x + lineWidth, y: rect.origin.y + lineWidth, width: rect.width - (lineWidth * 2), height: rect.height - (lineWidth * 2))
let path = UIBezierPath(ovalInRect: frame)
path.lineWidth = lineWidth

path.stroke()

// Draw X
let radius = (rect.width / 2) * 0.5
let center = CGPoint(x: rect.width / 2, y: rect.height / 2)

let π = CGFloat(M_PI)
let centerWidth = radius * cos(π/4)
let centerHeight = radius * sin(π/4)

path.lineWidth = lineWidth

path.moveToPoint(CGPoint(x: CGFloat(center.x + centerWidth), y: CGFloat(center.y + centerHeight)))
path.addLineToPoint(CGPoint(x: CGFloat(center.x - centerWidth), y: CGFloat(center.y - centerHeight)))
path.stroke()

path.lineWidth = lineWidth

path.moveToPoint(CGPoint(x: center.x - centerWidth, y: center.y + centerHeight))
path.addLineToPoint(CGPoint(x: center.x + centerWidth, y: center.y - centerHeight))
path.stroke()
}
}

这是结果:

我为我糟糕的英语道歉。

最佳答案

我相信您看到的是按钮的标题文本在图像上绘制的结果。在 Playground 中使用您的代码查看以下演示:

enter image description here

关于ios - 为什么使用 Core Graphics 绘制直线我得到 "dashed"行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com