This question belongs to View Building with SwiftUI , particularly the domain involving positioning and/or laying out a single SwiftUI view with standard views and modifiers . To place text on top of a shape such as a Capsule, SwiftUI uses the overlay modifier. Apple documents overlay as a view modifier that layers one view in front of another, which is exactly what is needed here: the text should appear on top of the blue capsule rather than beside or below it. The second blank must therefore be Text , because SwiftUI uses a Text view to display string content like " Great! " .
The completed code is:
struct ContentView: View {
var body: some View {
Capsule()
.fill(.blue)
.frame(width: 200.0, height: 100.0)
.overlay(
Text( " Great! " )
.font(.largeTitle)
)
}
}
This works because Capsule() creates the shape, .fill(.blue) gives it the blue color, .frame(width:height:) sets its size, and .overlay(...) places the Text( " Great! " ) directly above that shape. This is a standard SwiftUI composition pattern: build a base view, then apply modifiers to style it and layer additional content. In App Development with Swift objectives, this aligns with understanding standard views, modifiers, and layout techniques in SwiftUI.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit