J'ai lu quelques sujets sur mais ne peut pas appliquer à moi ... J'essaie d'appliquer une couleur de dégradé à un arc drawed avec un UIBezierPath
. Le problème est que mon dégradé remplit tout le cercle et pas seulement l'anneau.mis mon gradient à un arc de BezierPath
func layerWith(size: CGSize, color: UIColor) -> CALayer {
let layer: CAShapeLayer = CAShapeLayer()
var path: UIBezierPath = UIBezierPath()
let lineWidth: CGFloat = 2
layer.backgroundColor = nil
layer.path = path.cgPath
layer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
switch self {
case .ring:
path.addArc(withCenter: CGPoint(x: size.width/2, y: size.height/2),
radius: size.width/2,
startAngle: 0,
endAngle: CGFloat(2 * M_PI),
clockwise: false);
layer.fillColor = UIColor.clear.cgColor
layer.strokeColor = color.cgColor
layer.lineWidth = lineWidth
let colorGradStart = UIColor(red: 0/255, green: 209/255, blue: 192/255, alpha: 1.0)
let colorGradEnd = UIColor(red: 00/255, green: 99/255, blue: 91/255, alpha: 1.0)
let gradient = CAGradientLayer()
gradient.frame = path.bounds
gradient.colors = [colorGradStart.cgColor, colorGradEnd.cgColor]
let shapeMask = CAShapeLayer()
shapeMask.path = path.cgPath
gradient.mask = shapeMask
layer.addSublayer(gradient)
}
return layer
}
Donc, ce code, appliquez le dégradé à toute la forme remplie, moi j'ai juste besoin de l'arc.
CABezierPath? Ou UIBezierPath? –
Il n'y a pas de CABezierPah. Je suppose que vous voulez dire UIBezierPath? –
@ElTomato UIBezierPath, juste une erreur. Désolé – John