Complete the code to add a red background color to the Text view.
Text("Hello World") .background([1])
overlay modifier instead of background.The background modifier adds a background color behind the view. Here, Color.red sets a red background.
Complete the code to overlay a blue circle on top of the Text view.
Text("Hello") .overlay(Circle().fill([1]).frame(width: 100, height: 100))
background instead of overlay.fill on the Circle.The overlay modifier places a view on top of another. Here, a blue circle is drawn over the text.
Fix the error in the code to correctly add a yellow background with 50% opacity.
Text("SwiftUI") .background(Color.yellow[1])
.alpha which is not a SwiftUI method.To set opacity on a color in SwiftUI, use the .opacity() modifier after the color.
Fill both blanks to overlay a rounded rectangle with a green stroke and add a gray background.
Text("Overlay") .overlay(RoundedRectangle(cornerRadius: [1]).stroke([2])) .background(Color.gray)
The RoundedRectangle needs a corner radius number and a stroke color. Here, 10 and Color.green are correct.
Fill all three blanks to create a Text view with a blue background, overlay a red circle, and add padding of 20.
Text("Hello") .background([1]) .overlay(Circle().fill([2])) .padding([3])
The background is set to blue, the overlay circle is red, and padding is 20 points.