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]