Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create a view with size 400 x 400
- let view = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
- // Create a gradient layer
- let gradient = CAGradientLayer()
- // gradient colors in order which they will visually appear
- gradient.colors = [UIColor.red.cgColor, UIColor.blue.cgColor]
- // Gradient from left to right
- gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
- gradient.endPoint = CGPoint(x: 1.0, y: 0.5)
- // set the gradient layer to the same size as the view
- gradient.frame = view.bounds
- // add the gradient layer to the views layer for rendering
- view.layer.addSublayer(gradient)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement