NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

SOLVED: Day 24 - Challenge

Forums > 100 Days of SwiftUI

I was trying to solve Day 24 challenges.

Create a custom ViewModifier (and accompanying View extension) that makes a view have a large, blue font suitable for prominent titles in a view. - solved

""" struct Title: ViewModifier { func body(content: Content) -> some View { content .font(.largeTitle) .foregroundColor(.blue) } }

extension View{ func titlestyle1() -> some View { self.modifier(Title()) } }

""" Go back to project 1 and use a conditional modifier to change the total amount text view to red if the user selects a 0% tip.

-- I know paul said we cannot use If statements and frankly I dunno how to use it in the section where I am displaying the Total Amount for the check before dividing between all the participants.

I know that I capture Tipselections in the above method but I guess where I am stuck is to use this tip selection value and compare it with 0 so I can conditionally use to change the font. apprectiate any hints :)

Go back to project 2 and create a FlagImage() view that renders one flag image using the specific set of modifiers we had.

--> I am a little confused with the question.. Is paul asking us to to create a view that will only change the flag image of only 1 flag ? or create a general view modifier when applied will change for all the flags ?

appreciate your help !

   

In the case of project one, you can use the ternary operator, like:

Text("Total: $\(self.totalAmount)")
    .foregroundColor(tipAmounts[tipIndex] == 0 ? Color.red : Color.black)

For the second project, you'll have something like the following for each flag image:

Image(imageFileName)
            .renderingMode(.original)
            .clipShape(Capsule())
            .overlay(Capsule().stroke(Color.black, lineWidth: 2))
            .shadow(color: .black, radius: 2)

What he wants is that you create a new View type called FlagImage, that returns an Image with all those modifiers, so that you only have to use FlagImage(fileName: flagFileName) on your ContentView.

1      

Thank you so much for your help !!! you made my day .. now I can sleep well and come back for tomorrow's challenge :) I knew I was getting something wrong ... Appreciate your help !!!

   

Subscribe to Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.