跳转至
Structure

LazyVGrid

A container view that arranges its child views in a grid that grows vertically, creating items only as needed.

Declaration

struct LazyVGrid<Content> : View where Content : View

Overview

The grid is "lazy," in that the grid view does not create items until they are needed.

In the following example, a ScrollView contains a LazyVGrid consisting of a two-column grid of Text views, showing Unicode code points from the "Smileys" group and their corresponding emoji:

struct EmojiGridView: View {
    var columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2)

    var body: some View {
        ScrollView {
            LazyVGrid(columns: columns) {
                ForEach((0...79), id: \.self) {
                    let codepoint = $0 + 0x1f600
                    let codepointString = String(format: "%02X", codepoint)
                    Text("\(codepointString)")
                    let emoji = String(Character(UnicodeScalar(codepoint)!))
                    Text("\(emoji)")
                }
            }.font(.largeTitle)
        }
    }
}
D3F809F0-9891-47DC-8E95-99160DC1B7F5

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Initializer

init(columns:alignment:spacing:pinnedViews:content:) Creates a grid that grows vertically, given the provided properties.


Type Alias

Body The type of view representing the body of this view.