UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 !

3      

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.

7      

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 !!!

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.