Ich verwende Swift v2.2 und habe ein Rechteck wie unten gezeigt gezeichnet, das ich füllen möchte, um dann etwas weißen Text anzuzeigen. Ich sehe jedoch, dass der Pfad geschlossen wurde, aber das Rechteck nicht gefüllt wird. Bitte helfen und danke für jede Eingabe.Bezier close Pfad wird nicht gefüllt
-Code
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()
}
}
Layout-
Handy
Ansicht (wo Bezier Pfad gezeichnet wird)
- beschriftet (mit weißen Text)
Sollten Sie nicht rufen 'instructionRectPathColor.set()' 'vor instructionRectPath.fill () '? – beyowulf
Bevor Sie '.fill()' aufrufen, setzen Sie keine Farbe. Versuchen Sie, eine Codezeile nach unten zu bewegen, und Sie sollten sehen, dass sie dieselbe Farbe wie der Rahmen aufweist. Im Moment füllt es sich nur mit der Standardfarbe, die klar ist. – NSGangster