Bird
0
0

You want to create a Text view that shows "SwiftUI Rocks!" in large bold font, colored green, with padding around it. Which code snippet achieves this correctly?

hard📝 Application Q15 of 15
iOS Swift - SwiftUI Basics
You want to create a Text view that shows "SwiftUI Rocks!" in large bold font, colored green, with padding around it. Which code snippet achieves this correctly?
AText("SwiftUI Rocks!") .font(.bold.largeTitle) .foregroundColor(.green) .padding()
BText("SwiftUI Rocks!") .font(.largeTitle.bold) .foregroundColor(.green) .padding()
CText("SwiftUI Rocks!") .font(.largeTitle) .foregroundColor(.green.bold()) .padding()
DText("SwiftUI Rocks!") .font(.largeTitle.bold()) .foregroundColor(.green) .padding()
Step-by-Step Solution
Solution:
  1. Step 1: Apply bold to font correctly

    Using .font(.largeTitle.bold()) chains the bold style properly with the font size.
  2. Step 2: Set color and padding

    .foregroundColor(.green) sets the text color, and .padding() adds default padding around the text.
  3. Step 3: Check other options for errors

    Text("SwiftUI Rocks!") .font(.largeTitle).bold() .foregroundColor(.green) .padding() tries to call .bold() separately which is invalid on Font. Text("SwiftUI Rocks!") .font(.largeTitle) .foregroundColor(.green.bold()) .padding() tries to bold the color, which is incorrect. Text("SwiftUI Rocks!") .font(.bold.largeTitle) .foregroundColor(.green) .padding() uses invalid font syntax.
  4. Final Answer:

    Text("SwiftUI Rocks!") .font(.largeTitle.bold()) .foregroundColor(.green) .padding() -> Option D
  5. Quick Check:

    Use .font(.largeTitle.bold()) for bold large font [OK]
Quick Trick: Chain .bold() inside .font() for bold text [OK]
Common Mistakes:
  • Calling .bold() separately on Text or Font
  • Trying to bold the color
  • Using invalid font modifier order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes