Generic Structure

List

A container that presents rows of data arranged in a single column.

Declaration

struct List<SelectionValue, Content> where SelectionValue : Hashable, Content : View

Topics

Creating a List

init(content: () -> Content)

Setting the Size of a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions this view within an invisible frame with the specified size.

func fixedSize() -> View

Fixes this view at its ideal size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes this view at its ideal size in the specified dimensions.

Specifying the Relative Size of a View

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to this child.

Setting the Position of a View

func position(CGPoint) -> View

Fixes the center of this view at the specified point in its parent’s coordinate space.

func position(x: CGFloat, y: CGFloat) -> View

Fixes the center of this view at the specified coordinates in its parent’s coordinate space.

func offset(CGSize) -> View

Offsets this view by the horizontal and vertical distances in the given size.

func offset(x: CGFloat, y: CGFloat) -> View

Offsets this view by the specified horizontal and vertical distances.

func edgesIgnoringSafeArea(Edge.Set) -> View

Extends the view out of the safe area on the specified edges.

Aligning Views

func alignmentGuide(HorizontalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

Adjusting the Padding of a View

func padding(CGFloat) -> View

Pads this view along all edge insets by the amount you specify.

func padding(Edge.Set, CGFloat?) -> View

Pads this view using the edge insets you specify.

Setting the Foreground or Background of a View

Setting the Border of a View

func border<S>(S, width: CGFloat) -> View

Adds a border to this view with the specified style and width.

Masking and Clipping Views

func clipped(antialiased: Bool) -> View

Clips this view to its bounding rectangular frame.

func clipShape<S>(S, style: FillStyle) -> View

Sets a clipping shape for this view.

func cornerRadius(CGFloat, antialiased: Bool) -> View

Clips this view to its bounding frame, with the specified corner radius.

Scaling Views

Adjusting Text in a View

func font(Font?) -> View

Sets the default font for text in this view.

func lineLimit(Int?) -> View

Sets the maximum number of lines that text can occupy in this view.

func lineSpacing(CGFloat) -> View

Sets the amount of space between lines of text in this view.

func minimumScaleFactor(CGFloat) -> View

Sets the minimum amount that text in this view scales down to fit in the available space.

func truncationMode(Text.TruncationMode) -> View

Sets the truncation mode for lines of text that are too long to fit in the available space.

func allowsTightening(Bool) -> View

Sets whether text in this view can compress the space between characters when necessary to fit text in a line.

func flipsForRightToLeftLayoutDirection(Bool) -> View

Sets whether this view flips its contents horizontally when the layout direction is right-to-left.

Adding Animations to a View

func animation(Animation?) -> View

Applies the given animation to all animatable values within this view.

func animation<V>(Animation?, value: V) -> View

Applies the given animation to this view, whenever the specified value changes.

func transition(AnyTransition) -> View

Associates a transition with self.

Handling View Taps and Gestures

func itemProvider(Optional<() -> NSItemProvider?>) -> View

Provides a closure that vends the drag representation to be used for a particular DynamicContent.

func transaction((inout Transaction) -> Void) -> View

Applies the given transaction mutation function to all transactions used within the view.

Handling View Events

func onAppear(perform: (() -> Void)?) -> View

Adds an action to perform when this view appears.

func onDisappear(perform: (() -> Void)?) -> View

Adds an action to perform when this view disappears.

Handling View Hover and Focus

func onHover(perform: (Bool) -> Void) -> View

Adds an action to perform when the user moves the pointer over or away from this view’s frame.

func focusable(Bool, onFocusChange: (Bool) -> Void) -> View

Sets whether this view is focusable and, if so, adds an action to perform when the view comes into focus.

Supporting Drag and Drop in Views

func onDrag(() -> NSItemProvider) -> View

Activates this view as the source of a drag and drop operation.

func onDrop(of: [String], delegate: DropDelegate) -> View

Defines the destination for a drag and drop operation with the same size and position as this view, with behavior controlled by the given delegate.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider], CGPoint) -> Bool) -> View

Defines the destination for a drag and drop operation with the same size and position as this view, handling dropped content and the drop location with the given closure.

Adopting View Color Schemes

func colorScheme(ColorScheme) -> View

Sets this view’s color scheme.

func accentColor(Color?) -> View

Sets the accent color for this view and the views it contains.

Applying Blurs and Shadows to a View

Applying Graphical Effects to a View

func opacity(Double) -> View

Sets the transparency of this view.

func brightness(Double) -> View

Brightens this view by the specified amount.

func contrast(Double) -> View

Sets the contrast and separation between similar colors in this view.

func colorInvert() -> View

Inverts the colors in this view.

func colorMultiply(Color) -> View

Adds a color multiplication effect to this view.

func blendMode(BlendMode) -> View

Sets the blend mode for compositing this view with overlapping views.

func compositingGroup() -> View

Wraps this view in a compositing group.

func drawingGroup(opaque: Bool, colorMode: ColorRenderingMode) -> View

Composites this view’s contents into an offscreen image before final display.

func saturation(Double) -> View

Adjusts the color saturation of this view.

func grayscale(Double) -> View

Adds a grayscale effect to this view.

func hueRotation(Angle) -> View

Applies a hue rotation effect to this view.

func luminanceToAlpha() -> View

Adds a luminance to alpha effect to this view.

Configuring a List View

func listRowInsets(EdgeInsets?) -> View

Sets the inset to be applied to self in a List.

func listRowBackground<V>(V?) -> View

Sets the view to be placed behind self when placed in a List

func listRowPlatterColor(Color?) -> View

Sets the color to be apply to the system cell platter when self is placed in a List

Configuring Context Menu Views

func contextMenu<MenuItems>(ContextMenu<MenuItems>?) -> View

Attaches a ContextMenu and its children to self.

Configuring Touch Bar Views

func touchBar<Content>(TouchBar<Content>) -> View

Sets the TouchBar and its content to be shown in the Touch Bar when applicable

func touchBarItemPrincipal(Bool) -> View

Principal views have special significance to this TouchBar. Currently, that item will be placed in the center of the row.

func touchBarCustomizationLabel(Text) -> View

The user-visible String identifying the view’s functionality. Visible during user customization.

func touchBarItemPresence(TouchBarItemPresence) -> View

The behavior of the view when being customized by the user. Views may be:

Hiding and Disabling Views

func hidden() -> View

Hides this view.

func disabled(Bool) -> View

Adds a condition that controls whether users can interact with this view.

func deleteDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be deleted.

func moveDisabled(Bool) -> View

Adds a condition for whether the view hierarchy for self can be moved.

Setting View Preferences

func preference<K>(key: K.Type, value: K.Value) -> View

Returns a view producing value as the value of preference Key seen by its ancestors.

func transformPreference<K>(K.Type, (inout K.Value) -> Void) -> View

Returns a view that applies callback(&value) to the value of preference Key that’s seen by its ancestors.

Responding to View Preferences

func onPreferenceChange<K>(K.Type, perform: (K.Value) -> Void) -> View

Adds an action to perform when the specified preference key’s value changes.

func backgroundPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as as the background to self.

func overlayPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as an overlay on self.

Setting the Environment Values of a View

func environment<V>(WritableKeyPath<EnvironmentValues, V>, V) -> View

Returns a view wrapping self that sets a value for an environment keyPath.

func transformEnvironment<V>(WritableKeyPath<EnvironmentValues, V>, transform: (inout V) -> Void) -> View

Returns a view wrapping self that transforms the value of the environment key described by keyPath by applying a transform function.

Configuring a View for Hit Testing

func contentShape<S>(S, eoFill: Bool) -> View

Returns a new view that defines the content shape for hit-testing self as shape. eoFill defines whether the shape is interpreted using the even-odd winding number rule or not.

Configuring View Previews

func previewDevice(PreviewDevice?) -> View

Overrides the device for a preview.

func previewDisplayName(String?) -> View

Provides a user visible name shown in the editor.

func previewLayout(PreviewLayout) -> View

Overrides the size of the container for the preview.

Instance Properties

Instance Methods

func alignmentGuide(VerticalAlignment, computeValue: (ViewDimensions) -> CGFloat) -> View

Returns a view modified so that its value for the given guide is the result of passing the ViewDimensions of the underlying view to computeValue.

func aspectRatio(CGSize, contentMode: ContentMode) -> View

Constrains this view’s dimensions to the aspect ratio of the given size.

func defaultWheelPickerItemHeight(CGFloat) -> View

Sets the default .wheel style Picker item height within self.

func digitalCrownRotation<V>(Binding<V>) -> View

Tracks Digital Crown rotations by updating the given binding.

func onDrop(of: [String], isTargeted: Binding<Bool>?, perform: ([NSItemProvider]) -> Bool) -> View

Defines the destination for a drag and drop operation, using the same size and position as this view, handling dropped content with the given closure.

func padding(EdgeInsets) -> View

Pads this view using the edge insets you specify.

func tag<V>(V) -> View

Sets the tag of the view, used for selecting from a list of View options.

Relationships

Conforms To

See Also

Lists and Scroll Views

protocol DynamicViewContent

A type of view that generates views from an underlying collection of data.

Beta
protocol Identifiable

A class of types whose instances hold the value of an entity with stable identity.

Beta
struct ForEach

A structure that computes views on demand from an underlying collection of of identified data.

Beta
struct ScrollView

A scroll view.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software