OneScript

scaledToFill

Scale a view to fill while preserving its aspect ratio.

scaledToFill() scales a view to fill its proposed size while preserving the view's aspect ratio. It can be applied to any view. Overflow remains visible until a later modifier clips it.

import { Modifier, Symbol } from "onescript/views"

<Symbol
  source="pika"
  name="photo.image.default.fill"
  resizable
  modifier={Modifier
    .scaledToFill()
    .frame({ width: 240, height: 160 })
    .clipped()}
/>

For an Image or Symbol, enable resizable when the content should resize. Keep clipped() explicit so the modifier sequence controls the crop boundary.

For the SwiftUI semantics and layout behavior of this modifier, see Apple's scaledToFill() documentation.

How is this guide?

Last updated on