Bird
0
0

How can you display an asset image named "logo" as a template image so that tintColor affects it?

hard📝 Application Q9 of 15
iOS Swift - SwiftUI Basics
How can you display an asset image named "logo" as a template image so that tintColor affects it?
AUIImageView(image: UIImage(named: "logo")) with imageView.tintColor set
BUIImageView(image: UIImage(systemName: "logo"))
CUIImageView(image: UIImage(named: "logo")?.withRenderingMode(.alwaysTemplate))
DUIImageView(image: UIImage(named: "logo")?.withRenderingMode(.alwaysOriginal))
Step-by-Step Solution
Solution:
  1. Step 1: Use withRenderingMode(.alwaysTemplate) on asset image

    This makes the image render as a template, allowing tintColor to apply.
  2. Step 2: Assign the templated image to UIImageView

    Now tintColor will color the image as desired.
  3. Final Answer:

    UIImageView(image: UIImage(named: "logo")?.withRenderingMode(.alwaysTemplate)) -> Option C
  4. Quick Check:

    Template rendering mode enables tintColor on asset images [OK]
Quick Trick: Use withRenderingMode(.alwaysTemplate) to tint asset images [OK]
Common Mistakes:
  • Using systemName for asset images
  • Not setting rendering mode to template
  • Expecting tintColor to work without template mode

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes