Bird
0
0

What will be the padding around the Text view after this code runs?

medium📝 Predict Output Q5 of 15
iOS Swift - SwiftUI Basics
What will be the padding around the Text view after this code runs?
Text("Hi")
  .padding(10)
  .padding(5)
A10 points padding
B15 points padding (sum)
C5 points padding
DNo padding applied
Step-by-Step Solution
Solution:
  1. Step 1: Understand how padding modifiers stack

    Each padding modifier wraps the previous view with additional padding around it.
  2. Step 2: Identify total padding value

    The first .padding(10) adds 10 points around the Text, then .padding(5) adds 5 more points around that padded view, resulting in 15 points total padding.
  3. Final Answer:

    5 points padding -> Option C
  4. Quick Check:

    Later padding overrides earlier padding [OK]
Quick Trick: Later padding overrides earlier padding [OK]
Common Mistakes:
  • Thinking later padding overrides earlier padding
  • Assuming first padding determines the total
  • Ignoring modifier order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes