2
我在我的视图中创建了简单的边界线。不过,我正在努力为其提供水平渐变背景色。我应该怎么做?将水平渐变添加到边界
我想这样的,但它只是颜色设置为白色:
let border = CAGradientLayer()
border.frame = CGRect(x: 0, y: self.mainView.frame.height - 2, width: self.mainView.frame.width, height: 2)
border.backgroundColor = UIColor.gray.cgColor
let color1 = UIColor.black.withAlphaComponent(0.1).cgColor as CGColor
let color2 = UIColor.white.withAlphaComponent(0.9).cgColor as CGColor
border.locations = [0.60, 1.0]// Are these right coordinates?
border.colors = [color2, color1]