美文网首页
swift绘制圆角加阴影

swift绘制圆角加阴影

作者: 男人宫 | 来源:发表于2020-03-31 15:54 被阅读0次
    class MineTopView: UIView {
        
        override func draw(_ rect: CGRect) {
            //避免重复绘制
            layer.sublayers?.forEach({ obj in
                if obj.isKind(of: CAGradientLayer.self) {
                    obj.removeFromSuperlayer()
                }
            })
            let gradient = CAGradientLayer()
            gradient.colors = [UIColor(red: 0.12, green: 0.61, blue: 0.93, alpha: 1).cgColor, UIColor(red: 0, green: 0.91, blue: 1, alpha: 1).cgColor]
            gradient.frame = self.bounds
            gradient.startPoint = CGPoint(x: 0, y: 0)
            gradient.endPoint = CGPoint(x: 1, y: 0)
            gradient.shadowColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 0.5).cgColor
            gradient.shadowOffset = CGSize(width: 0, height: 0)
            gradient.shadowOpacity = 0.8
            gradient.shadowRadius = 10
            gradient.cornerRadius = 8
            layer.insertSublayer(gradient, at: 0)
            
        }
        
    }
    

    相关文章

      网友评论

          本文标题:swift绘制圆角加阴影

          本文链接:https://www.haomeiwen.com/subject/rlowuhtx.html