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