【发布时间】:2018-03-07 22:17:23
【问题描述】:
TL;DR
有谁知道如何在径向渐变中平滑从红色到白色的渐变过渡?因为我的渐变中出现了难看的灰色。
详情:
我在draw rect中创建了一个自定义UIView
override func draw(_ rect: CGRect) {
let colors = [UIColor.red.cgColor, UIColor.clear.cgColor] as CFArray
let divisor: CGFloat = 3
let endRadius = sqrt(pow(frame.width/divisor, 2) + pow(frame.height/divisor, 2))
let center = CGPoint(x: bounds.midX, y: bounds.midY)
let gradient = CGGradient(colorsSpace: nil, colors: colors, locations: nil)
let context = UIGraphicsGetCurrentContext()
context?.saveGState()
context?.drawRadialGradient(gradient!,
startCenter: center,
startRadius: 0.0,
endCenter: center,
endRadius: endRadius,
options: .drawsBeforeStartLocation)
context?.restoreGState()
}
我将自定义视图的颜色设置为红色,并将视图添加到视图控制器的视图中,该视图具有白色背景。
我希望渐变从红色变为白色,但它似乎从红色变为灰色。我尝试将渐变数组中的第二种颜色更改为白色,虽然看起来确实稍微好一些,但灰度仍然存在。
【问题讨论】:
标签: ios core-graphics radial-gradients