Bird
0
0

You want to create a Text view that is italic, bold, and has a font size of 20. Which of the following code snippets achieves this correctly?

hard📝 Application Q8 of 15
iOS Swift - SwiftUI Basics
You want to create a Text view that is italic, bold, and has a font size of 20. Which of the following code snippets achieves this correctly?
AText("Hello").fontSize(20).italic().bold()
BText("Hello").italic().bold().font(.system(size: 20))
CText("Hello").bold().italic().fontSize(20)
DText("Hello").font(.system(size: 20)).bold().italic()
Step-by-Step Solution
Solution:
  1. Step 1: Confirm valid modifiers and order

    Modifiers .italic(), .bold(), and .font(.system(size:)) are valid, but order matters: apply .font first, then style modifiers like .bold() and .italic().
  2. Step 2: Identify invalid syntax and order

    .fontSize() does not exist, so options A and C are invalid. Text("Hello").italic().bold().font(.system(size: 20)) applies styles before .font, causing .font to override styles to regular weight.
  3. Final Answer:

    Text("Hello").font(.system(size: 20)).bold().italic() -> Option D
  4. Quick Check:

    Use .italic(), .bold(), and .font(.system(size:)) correctly = B [OK]
Quick Trick: Use .font(.system(size:)) for size, .bold() and .italic() for style [OK]
Common Mistakes:
  • Using non-existent .fontSize() modifier
  • Incorrect modifier chaining syntax
  • Applying style modifiers before font modifier

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes