In my project I have TableView which consist GMSMapView . I want to show gradient to GMSMapView . I have tried following code
class Colors {
let colorTop = UIColor(red: 192.0/255.0, green: 38.0/255.0, blue: 42.0/255.0, alpha: 1.0).CGColor
let colorBottom = UIColor(red: 35.0/255.0, green: 2.0/255.0, blue: 2.0/255.0, alpha: 1.0).CGColor
let gl: CAGradientLayer
init() {
gl = CAGradientLayer()
gl.colors = [ colorTop, colorBottom]
gl.locations = [ 0.0, 1.0]
}
}
And this Code in TableView Cell's Class
class AllTripTableViewCell: UITableViewCell {
var colors = Colors()
func refresh() {
mapView.backgroundColor = UIColor.clearColor()
let backgroundLayer = colors.gl
backgroundLayer.frame = mapView.frame
mapView.layer.insertSublayer(backgroundLayer, atIndex: 0)
}
}
and use like this
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("AllTrip", forIndexPath: indexPath) as! AllTripTableViewCell
cell.refresh()
}
But It doest Show gradient Layer