使用 UIBezierPath,我试图在自定义 UIView 的灰色背景“之上”创建一个黄色圆角矩形。如果您能帮助我理解为什么此代码片段不起作用,我将不胜感激:
class CardView: UIView {
override func draw(_ rect: CGRect) {
let roundedRect = UIBezierPath(roundedRect: bounds, cornerRadius: 16.0)
UIColor.yellow.setFill()
roundedRect.fill()
}
}
感谢您的帮助!
最佳答案
我想通了。 . .我没有调用 addClip() 方法。
class CardView: UIView {
override func draw(_ rect: CGRect) {
let roundedRect = UIBezierPath(roundedRect: bounds, cornerRadius: 16.0)
roundedRect.addClip()
UIColor.yellow.setFill()
roundedRect.fill()
}
现在可以了。
关于swift - 如何只填充自定义 UIView 矩形的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56688251/