1。创建 渐变色
/// 渐变色:默认从上到下 private var gradIEntLayer: CAGradIEntLayer = { let g = CAGradIEntLayer() g.colors = [UIcolor.init(hexcolor: "DBB479").cgcolor,UIcolor.init(hexcolor: "F7E1B3").cgcolor] //改为从左到右 的渐变 g.startPoint = CGPoint(x: 0,y: 0) g.endPoint = CGPoint(x: 1,y: 0) return g }()
2.给指定vIEw 添加渐变色
/// 荣誉背景图 private lazy var credibilityBgVIEw : UIVIEw = { let v = UIVIEw() v.layer.addSublayer(self.gradIEntLayer) v.translatesautoresizingMaskIntoConstraints = false v.layer.cornerRadius = 5 v.layer.masksToBounds = true v.isUserInteractionEnabled = true v.addGestureRecognizer(UITapGestureRecognizer(target: self,action: #selector(clcikCredibilityBgVIEw))) return v }()
3. 设置 渐变色frame
overrIDe func draw(_ rect: CGRect) { super.draw(rect) gradIEntLayer.frame = credibilityBgVIEw.bounds }总结
以上是内存溢出为你收集整理的swift - layer - 渐变色 - CAGradientLayer全部内容,希望文章能够帮你解决swift - layer - 渐变色 - CAGradientLayer所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)