跳转至
Enumeration

ContentMode

Constants that define how a view's content fills the available space.

Declaration

@frozen enum ContentMode : Hashable, CaseIterable

Overview

Use this enumeration along with the aspectRatio(_:contentMode:) and aspectRatio(_:contentMode:) modifiers to specify how to change the aspect ratio of a view.

This enum has 2 options:

  1. fit: Scale the content so that it can be fully seen in the available space.
  2. fill: Scale the content so that it fully fills the available space.

In the following example, we scale the ellipse down so that it fits perfectly in the space.

struct ContentView: View {
    var body: some View {
        VStack {
            Ellipse()
                .aspectRatio(1.5, contentMode: ContentMode.fit)
                .frame(width: 200, height: 200)
                .border(Color.orange)
            Ellipse()
                .aspectRatio(1.5, contentMode: ContentMode.fill)
                .frame(width: 200, height: 200)
                .border(Color.orange)
        }
    }
}
A screenshot displaying two identical orange square outlines on top of each other. In the top one, there is a black ellipse that fits within the confines of the square. The bottom one has a black ellipse that fills the square vertically, taking up nearly all the space in the square.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Instance Method

hash(into:) Hashes the essential components of this value by feeding them into the given hasher.


Case

fill Fill mode that scales the view so that it fills the available space entirely, even if not all of the view can be seen.

fit Fill mode that scales down view so that it can be fully seen in the available space, even it it leaves whitespace.


Type Alias

AllCases A type that can represent a collection of all values of this type.


Type Property

allCases A collection of all values of this type.


Type Method

==(a:b:) Returns a Boolean value indicating whether two values are equal.


Instance Property

hashValue The hash value.