【发布时间】:2018-03-28 02:44:21
【问题描述】:
我不明白这个函数实际上是如何工作的 如果我想更改“视图”的背景颜色,我将访问视图的背景属性并更改它的值
let containerView = CustomView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
containerView.backgroundColor = UIColor.blue
但是当我想在 draw() 函数中改变矩形的颜色时 我只是调用 UIColor.green.set() 函数。为什么这个函数会改变矩形的颜色
class CustomView: UIView {
override func draw(_ rect: CGRect) {
super.draw(rect)
let rect = UIBezierPath(roundedRect: CGRect(x: 150, y: 150, width: 100, height: 100), cornerRadius: 5.0)
UIColor.green.set() // <- Why this line change rect color ?
rect.fill()
}
}
【问题讨论】:
-
嗨,@Moritz 抱歉,我正在尝试修复它。
-
现在好多了。请继续改进它。祝你好运! :)
-
非常感谢谢谢@Moritz
标签: ios swift cocoa-touch uiview uicolor