尝试添加渐变,添加圆角并在UIView
. 我可以让它工作,但渐变的位置不正确。(应该全部换成红色)
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [UIColor(red: 0.333, green: 0.376, blue: 0.498, alpha: 1.00).cgColor, UIColor(red: 0.200, green: 0.247, blue: 0.369, alpha: 1.00).cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 1, y: 0.75)
gradientLayer.frame = self.viewBg.bounds
//self.viewBg.layer.insertSublayer(gradientLayer, at: 0)
self.viewBg.layer.cornerRadius = 10
self.viewBg.layer.shadowColor = UIColor.black.cgColor
self.viewBg.layer.shadowOffset = CGSize(width: 7, height: 7)
self.viewBg.layer.shadowRadius = 10
self.viewBg.layer.shadowOpacity = 1
let inset: CGFloat = bounds.width * 0.05
self.viewBg.layer.shadowPath = UIBezierPath(roundedRect: bounds.insetBy(dx: inset, dy: 0.0), cornerRadius: 10).cgPath