0
我使用的是Swift v2.2,我画了一个矩形,如下图所示,我打算填充它,然后在其中显示一些白色文本。但是,我看到路径已关闭,但矩形未填充。请帮助并感谢您的任何意见。Bezier关闭路径没有得到填充
代码
class InstructionArrowBorderView: UIView {
var lineWidth: CGFloat = 1 {didSet { setNeedsDisplay() } }
var instructionRectPathColor: UIColor = UIColor(red:13/255.0, green:118/255.0, blue:255/255.0, alpha: 1.0) { didSet { setNeedsDisplay() } }
override func drawRect(rect: CGRect) {
let instructionRectPath = UIBezierPath()
instructionRectPath.moveToPoint(CGPoint(x: bounds.minX, y: bounds.maxY - 50))
instructionRectPath.addLineToPoint(CGPoint(x: bounds.minX, y: bounds.minY))
instructionRectPath.moveToPoint(CGPoint(x: bounds.minX, y: bounds.minY))
instructionRectPath.addLineToPoint(CGPoint(x: bounds.maxX, y: bounds.minY))
instructionRectPath.moveToPoint(CGPoint(x: bounds.maxX, y: bounds.minY))
instructionRectPath.addLineToPoint(CGPoint(x: bounds.maxX, y: bounds.maxY - 50))
instructionRectPath.moveToPoint(CGPoint(x: bounds.maxX, y: bounds.maxY - 50))
instructionRectPath.addLineToPoint(CGPoint(x: bounds.minX, y: bounds.maxY - 50))
instructionRectPath.lineWidth = lineWidth
instructionRectPath.closePath()
instructionRectPath.fill()
instructionRectPathColor.set()
instructionRectPath.stroke()
}
}
布局
细胞
视图(如果贝塞尔曲线的路径绘制)
- 标签(白字)
你不应该叫'instructionRectPathColor.set()''之前instructionRectPath.fill( )'? – beyowulf
在调用'.fill()'之前,您没有设置颜色,只需将它向下移动一行代码即可,并且您应该看到它使用与边框相同的颜色填充。现在只需填写默认的颜色即可。 – NSGangster