-
Notifications
You must be signed in to change notification settings - Fork 3
iOS CALayer
Kevin Leong edited this page Dec 21, 2016
·
4 revisions
class MyView: UIView {
override func draw(_ rect: CGRect) {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = layer.bounds
gradientLayer.colors = [UIColor.red.cgColor, UIColor.green.cgColor, UIColor.yellow.cgColor]
/**
Defaults:
start point x: 0.5, y: 0.0
end point x: 0.5, y: 1.0
Results in a vertical line segment, which the gradient always goes
perpendicular to.
Default gradient, therefore, goes from top to bottom.
To achieve a left to right gradient, set the start and end points
along a horizontal line, where the start point is to the left
of the end point.
*/
gradientLayer.startPoint = CGPoint(x: 0, y: 1)
gradientLayer.endPoint = CGPoint(x: 1, y: 1)
layer.addSublayer(gradientLayer)
}
}
- Apple Developer
- CATransform3DMakeRotation Axis - O Reilly