0
我製作了三角形視圖,名爲UpTriangleView。它用於顯示投票。當他們被挖掘時,我想改變他們的顏色。我想從實例UIColor.grayColor().setStroke()
,但我不知道如何做到這一點。如果你知道,請告訴我如何去做。謝謝你的愛。如何在Swift上使用drawRect更改三角形的顏色
class UpTriangleView: UIView {
override func drawRect(rect: CGRect) {
self.backgroundColor = UIColor.clearColor()
// Get Height and Width
let layerHeight = self.layer.frame.height
let layerWidth = self.layer.frame.width
// Create Path
let line = UIBezierPath()
// Draw Points
line.moveToPoint(CGPointMake(0, layerHeight))
line.addLineToPoint(CGPointMake(layerWidth, layerHeight))
line.addLineToPoint(CGPointMake(layerWidth/2, 0))
line.addLineToPoint(CGPointMake(0, layerHeight))
line.closePath()
// Apply Color
UIColor.grayColor().setStroke()
UIColor.grayColor().setFill()
line.lineWidth = 3.0
line.fill()
line.stroke()
// Mask to Path
let shapeLayer = CAShapeLayer()
shapeLayer.path = line.CGPath
self.layer.mask = shapeLayer
}
}
class QATableViewCell : UITableViewCell{
@IBOutlet weak var upTriangleView: UpTriangleView!
}
謝謝vacawama !!我懂了!!!! – lalala
謝謝vacawama ...它像一個魅力工作...真的很有幫助。 –