Author
Travis Kirton


Stretching Images

This example shows how you can stretch and set the size of an image.

Width

You can set the width of an image like so:

img.width = 100.0

Height

You can set the height of an image like so:

img.height = 100.0

Frame

You can set the frame of an image like so:

img.frame = canvas.frame

If you set constrainsProportions to true then the image’s scale will be preserved when setting width or height

Example

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)