swift Swift - CAGradientLayer
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift Swift - CAGradientLayer相关的知识,希望对你有一定的参考价值。
//See: https://www.raywenderlich.com/169004/calayer-tutorial-ios-getting-started
func cgColor(red: CGFloat, green: CGFloat, blue: CGFloat) -> CGColor {
return UIColor(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: 1.0).cgColor
}
let gradientLayer = CAGradientLayer()
gradientLayer.frame = someView.bounds
gradientLayer.colors = [cgColor(red: 209.0, green: 0.0, blue: 0.0),
cgColor(red: 255.0, green: 102.0, blue: 34.0),
cgColor(red: 255.0, green: 218.0, blue: 33.0),
cgColor(red: 51.0, green: 221.0, blue: 0.0),
cgColor(red: 17.0, green: 51.0, blue: 204.0),
cgColor(red: 34.0, green: 0.0, blue: 102.0),
cgColor(red: 51.0, green: 0.0, blue: 68.0)]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 0, y: 1)
someView.layer.addSublayer(gradientLayer)
以上是关于swift Swift - CAGradientLayer的主要内容,如果未能解决你的问题,请参考以下文章
Swift入门系列--Swift官方文档(2.2)--中文翻译--About Swift 关于Swift
swift 示例BS swift.swift
swift swift_bug.swift
ios 整理(一)swift和oc的区别
swift swift_extension5.swift
swift swift_optional4.swift