0
0
iOS Swiftmobile~20 mins

Text view and modifiers in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Text Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the color of the text shown?
Consider this SwiftUI code snippet. What color will the text appear on screen?
iOS Swift
Text("Hello SwiftUI")
  .foregroundColor(.red)
  .background(Color.yellow)
AYellow text on red background
BRed text on yellow background
CBlack text on yellow background
DRed text on transparent background
Attempts:
2 left
💡 Hint
The foregroundColor modifier changes the text color, background changes behind the text.
📝 Syntax
intermediate
2:00remaining
Which code correctly makes the text bold and italic?
Choose the SwiftUI code that applies both bold and italic styles to the text.
AText("SwiftUI").bold().italic()
BText("SwiftUI").font(.bold).italic()
CText("SwiftUI").fontWeight(.bold).italic()
DText("SwiftUI").italic().bold()
Attempts:
2 left
💡 Hint
bold() and italic() are modifiers that can be chained in any order.
lifecycle
advanced
2:00remaining
What happens if you apply multiple foregroundColor modifiers?
Given this code, what color will the text display?
iOS Swift
Text("Hello")
  .foregroundColor(.blue)
  .foregroundColor(.green)
AText with gradient from blue to green
BBlue text
CGreen text
DText with default color
Attempts:
2 left
💡 Hint
Later modifiers override earlier ones.
🔧 Debug
advanced
2:00remaining
Why does this code cause a compile error?
Identify the error in this SwiftUI code snippet:
iOS Swift
Text("Welcome")
  .fontWeight("bold")
AMissing parentheses after fontWeight
BText cannot have fontWeight modifier
CfontWeight must be called before Text()
DfontWeight expects a Font.Weight value, not a String
Attempts:
2 left
💡 Hint
Check the type of argument fontWeight expects.
🧠 Conceptual
expert
2:00remaining
How does the order of modifiers affect the final text appearance?
Given these two code snippets, which statement is true about their rendered text?
AText("Hi").padding().background(Color.gray) adds padding inside the background
BText("Hi").background(Color.gray).padding() adds padding inside the background
CBoth snippets produce identical UI
DPadding and background order does not affect layout
Attempts:
2 left
💡 Hint
Think about what area the background color covers relative to padding.