You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Overlay works using the concept of layered images. Each layer represents an individual image that can then be added atop another layer. You can think of this like layers in Photoshop, or similar image editor.
For example, take the following model:
Layer 0: A large blue square
Layer 1: A medium orange triangle
Layer 2: A small green polygon
Technical Note: For this guide, we will assume that these images are named "Square", "Triangle", and "Polygon" in our app's Asset Catalog, and they are all formatted as PNG images with a transparent background.
A collection of images organized into layers is represented in code using the Layers class.
// Create a dictionary of all the images and layers we want to create.
// This will then be passed to Layers
letlayerDictionary:[Int:String]=[0:"Square",1:"Triangle",2:"Polygon"]
// Create the new layers object.
guardlet layers =try?Layers(named: layerDictionary)else{
// Some error occurred
return}
Alternatively, you could create a dictionary using UIImage objects:
letlayerDictionary:[Int:UIImage]
And pass it to Layers.init(with:)
Now we have a layered image represented in Swift!
Rendering Layers
Of course, we want to be able to use our new composite image. To do that we use OverlayRenderer
// Create a new renderer
letrenderer=OverlayRenderer()
renderer.composite(from: layers){ result in
// Here we can access the completed render
}
The result:
To see this in action, check out the Sample App included in the source code.
Layer Operations
You can insert, append, and remove layers from a Layers object.
See the Layers Guide