SwiftDeveloper
SwiftDeveloper

Reputation: 7370

How to add color over CALayer() with alpha value?

I have working slideshow codes with CALayer() and I want to add Brown color mask over images with alpha value. My CALayer() codes under below.

   let imageLayer = CALayer()
    imageLayer.contents = image.cgImage
    imageLayer.anchorPoint = CGPoint.zero
    imageLayer.bounds = CGRect(origin: CGPoint.zero, size: optimus)
    imageLayer.position = origin
    imageView.layer.addSublayer(imageLayer)

Full code you can see here: https://github.com/Gatada/JBKenBurnsView/blob/master/KenBurns/JBKenBurnsView.swift. Look at 281-286 lines between.

Upvotes: 0

Views: 1807

Answers (1)

Nirav D
Nirav D

Reputation: 72410

Try like this.

imageLayer.backgroundColor = UIColor.brown.withAlphaComponent(0.8).cgColor //Set alpha you want

Edit: From your edit code you need to set your imageLayer2 frame like this.

imageLayer2.frame = imageView.bounds

Upvotes: 1

Related Questions