iOS Swift - SwiftUI LayoutWhich of the following is the correct syntax to horizontally center a Text view in SwiftUI?AText("Hello").frame(maxWidth: .infinity, alignment: .center)BText("Hello").frame(maxWidth: .infinity, alignment: .leading)CText("Hello").frame(width: 100, alignment: .trailing)DText("Hello").frame(height: 50, alignment: .center)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand frame modifier with alignmentframe(maxWidth: .infinity) expands width, alignment: .center centers content horizontally.Step 2: Identify correct alignment for horizontal centeringalignment: .center centers the Text horizontally inside the frame.Final Answer:Text("Hello").frame(maxWidth: .infinity, alignment: .center) -> Option AQuick Check:Center horizontally = alignment: .center with maxWidth infinity [OK]Quick Trick: Use maxWidth: .infinity and alignment: .center to center horizontally [OK]Common Mistakes:Using .leading or .trailing for centeringSetting fixed width without maxWidthAligning vertically instead of horizontally
Master "SwiftUI Layout" in iOS Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepUITryChallengeBuildRecallPublish
More iOS Swift Quizzes State Management in SwiftUI - @StateObject for observable objects - Quiz 13medium State Management in SwiftUI - @Binding for child communication - Quiz 4medium Swift Language Essentials - Variables (let, var) and type inference - Quiz 7medium SwiftUI Basics - Text view and modifiers - Quiz 8hard SwiftUI Basics - Text view and modifiers - Quiz 11easy SwiftUI Basics - Text view and modifiers - Quiz 1easy SwiftUI Basics - Image view (system and asset) - Quiz 2easy SwiftUI Layout - Why layout controls visual structure - Quiz 7medium User Input and Forms - Slider - Quiz 3easy User Input and Forms - Why forms capture structured data - Quiz 14medium