<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/UIHostingConfiguration",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI22UIHostingConfigurationV"
  },
  "title" : "UIHostingConfiguration"
}
-->

# UIHostingConfiguration

A content configuration suitable for hosting a hierarchy of SwiftUI views.

```
struct UIHostingConfiguration<Content, Background> where Content : View, Background : View
```

## Overview

Use a value of this type, which conforms to the
<doc://com.apple.documentation/documentation/UIKit/UIContentConfiguration-9eib5>
protocol, with a
<doc://com.apple.documentation/documentation/UIKit/UICollectionViewCell> or
<doc://com.apple.documentation/documentation/UIKit/UITableViewCell> to host
a hierarchy of SwiftUI views in a collection or table view, respectively.
For example, the following shows a stack with an image and text inside the
cell:

```
myCell.contentConfiguration = UIHostingConfiguration {
    HStack {
        Image(systemName: "star").foregroundStyle(.purple)
        Text("Favorites")
        Spacer()
    }
}
```

You can also customize the background of the containing cell. The following
example draws a blue background:

```
myCell.contentConfiguration = UIHostingConfiguration {
    HStack {
        Image(systemName: "star").foregroundStyle(.purple)
        Text("Favorites")
        Spacer()
    }
}
.background {
    Color.blue
}
```

When used in a list layout, certain APIs are bridged automatically, like
swipe actions and separator alignment. The following example shows a
trailing yellow star swipe action:

```
cell.contentConfiguration = UIHostingConfiguration {
    HStack {
        Image(systemName: "airplane")
        Text("Flight 123")
        Spacer()
    }
    .swipeActions {
        Button { ... } label: {
            Label("Favorite", systemImage: "star")
        }
        .tint(.yellow)
    }
}
```

## Topics

### Creating and updating a configuration

[`init(content:)`](/documentation/SwiftUI/UIHostingConfiguration/init(content:))

Creates a hosting configuration with the given contents.

### Setting the background

[`background(_:)`](/documentation/SwiftUI/UIHostingConfiguration/background(_:))

Sets the background contents for the hosting configuration’s enclosing
cell.

[`background(content:)`](/documentation/SwiftUI/UIHostingConfiguration/background(content:))

Sets the background contents for the hosting configuration’s enclosing
cell.

### Setting margins

[`margins(_:_:)`](/documentation/SwiftUI/UIHostingConfiguration/margins(_:_:))

Sets the margins around the content of the configuration.

### Setting a size

[`minSize(width:height:)`](/documentation/SwiftUI/UIHostingConfiguration/minSize(width:height:))

Sets the minimum size for the configuration.

[`minSize()`](/documentation/SwiftUI/UIHostingConfiguration/minSize())

Sets the minimum size for the configuration.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)