Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the equivalent of CAGradientLayer in swift?

I'm trying to port over some objective-C code that creates a gradient layer

CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = colors;
gradientLayer.locations = locations;
gradientLayer.frame = view.bounds;

[view.layer insertSublayer:gradientLayer atIndex:index];

However in Swift, CAGradientLayer does not seem to have a static 'layer' method or a constructor. Trying to use it as a type produces:

let a:CAGradientLayer? = null

Error: Use of module 'CAGradientLayer' as a type

As far as I can tell, CAGradientLayer is not a module I can import. What's the correct way of doing a gradient layer in Swift?

like image 839
Mike Richards Avatar asked Jun 04 '14 00:06

Mike Richards


1 Answers

You need to import QuartzCore first:

import QuartzCore

let a:CAGradientLayer = CAGradientLayer()
like image 103
Austin Avatar answered Oct 07 '22 18:10

Austin