iOS Swift 绘图篇 - 01 扇形渐变
效果图
override func draw(_ rect: CGRect) {
let centerPoint = CGPoint(x: rect.width/2, y: rect.height/2)
let radiusLength = rect.width/2
let color = UIColor.blue
color.set()
let endValue: Int = 30
let startA = (CGFloat)((270/180)*Double.pi)
let endA = (CGFloat)(((Double(endValue) + 270.0)/180)*Double.pi)
let aPath = UIBezierPath()
aPath.move(to: centerPoint)
aPath.addArc(withCenter: centerPoint, radius: radiusLength, startAngle: endA, endAngle: startA, clockwise: false)
aPath.stroke()
let context = UIGraphicsGetCurrentContext()
for i in 0...endValue {
let color = UIColor(red: 1.0, green: 0, blue: 0.0, alpha: CGFloat(i)/CGFloat(endValue*2))
context?.setFillColor(color.cgColor)
context?.setLineWidth(0)
context?.move(to: centerPoint)
context?.addArc(center: centerPoint, radius: radiusLength, startAngle: CGFloat(Double(269 + i) * Double.pi / 180), endAngle: CGFloat(Double(270 + i) * Double.pi / 180), clockwise: false)
context?.closePath()
context?.drawPath(using: CGPathDrawingMode.fillStroke)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)