iOS Swift - SwiftUI LayoutWhich of the following is the correct syntax to add a blue background color to a Text view in SwiftUI?AText("Hello").background = Color.blueBText("Hello").overlay(Color.blue)CText("Hello").background(Color.blue)DText("Hello").background(Color("blue"))Check Answer
Step-by-Step SolutionSolution:Step 1: Check correct modifier usageThe .background() modifier is called as a function with a view parameter, like Color.blue.Step 2: Identify syntax errorsText("Hello").background = Color.blue uses assignment which is invalid. Text("Hello").background(Color("blue")) uses string initializer incorrectly. Text("Hello").overlay(Color.blue) uses overlay, not background.Final Answer:Text("Hello").background(Color.blue) -> Option CQuick Check:Correct syntax for background = Text("Hello").background(Color.blue) [OK]Quick Trick: Use .background(Color.colorName) with parentheses [OK]Common Mistakes:Using assignment instead of modifier callConfusing overlay with backgroundPassing color name as string incorrectly
Master "SwiftUI Layout" in iOS Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepUITryChallengeBuildRecallPublish
More iOS Swift Quizzes State Management in SwiftUI - ObservableObject protocol - Quiz 2easy State Management in SwiftUI - @StateObject for observable objects - Quiz 13medium Swift Language Essentials - Collections (Array, Dictionary, Set) - Quiz 2easy Swift Language Essentials - Collections (Array, Dictionary, Set) - Quiz 6medium Swift Language Essentials - Why Swift is designed for safety and speed - Quiz 6medium SwiftUI Basics - Text view and modifiers - Quiz 15hard SwiftUI Layout - Frame modifier - Quiz 1easy SwiftUI Layout - LazyVStack and LazyHStack - Quiz 15hard User Input and Forms - Keyboard management - Quiz 12easy iOS Basics and Setup - Creating a new iOS project - Quiz 10hard