This example shows how you can stretch and set the size of an image.
You can set the width
of an image like so:
img.width = 100.0
You can set the height
of an image like so:
img.height = 100.0
You can set the frame
of an image like so:
img.frame = canvas.frame
If you set
constrainsProportions
totrue
then the image’s scale will be preserved when settingwidth
orheight
let normal = Image("rockies")!
normal.center = canvas.center
let tall = Image(c4image: normal)
tall.height = canvas.height
tall.center = canvas.center
let wide = Image(c4image: normal)
wide.width = canvas.width
wide.center = canvas.center
let full = Image(c4image: normal)
full.frame = canvas.frame
self.canvas.add(full)
let images = [normal, tall, wide, full]
for img in images {
img.opacity = 0.66
img.border.color = white
img.border.width = 0.5
}
canvas.add(full)
canvas.add(tall)
canvas.add(wide)
canvas.add(normal)