100 Days of SwiftUI Day 24

100 Days of SwiftUI – Day 24 – Project #3 Review

It’s day 24 of the 100 Days of SwiftUI! Yesterday, we learned a lot about the internal workings of SwiftUI, as well as a lot about views and modifiers. Today, we’re wrapping up our third project with a few challenges. Let’s dive in!

SwiftUI challenges from project #3

The first challenge had us revisit the WeSplit app, our first project. The assignment: use a conditional modifier to change the total amount text view to red if the user selects a 0% tip.

Section {
          Text(grandTotal, format: currencyFormatter)
          } header: {
             Text("Grand total")
          }
          .foregroundColor(tipPercentage == 0 ? .red : .black)

The second challenge had us revisit our Guess the Flag app, the second project we completed: replace the Image view used for flags with a new FlagImage() view that renders one flag image using the specific set of modifiers we had.

struct FlagImage: View {
        
        var countries: [String]
        var number: Int
        
        var body: some View {
            
            Image(countries[number])
                .renderingMode(.original)
                .clipShape(Capsule())
                .shadow(radius: 5)
        }
    }

ForEach(0..<3) { number in
                        Button {
                            flagTapped(number)
                        } label: {
                            FlagImage(countries: countries, number: number)
                        }
                    }

The third challenge I implemented in our Guess the Flag app as well: create a custom ViewModifier (and accompanying View extension) that makes a view have a large, blue font suitable for prominent titles in a view.

struct largeBlueFont: ViewModifier {
    func body(content: Content) -> some View {
        content
        
            .font(.largeTitle.bold())
            .foregroundStyle(.blue)
    }
}

Text("Guess the Flag")
                    .largeBlueTitle()

And that’s it for day 24! It was a bit short, but I feel I have a decent grasp on everything we’ve learned on views and modifiers. Tomorrow is our second consolidation day, where we revisit everything we’ve learned from day 16 onwards, as well as a challenge. Time fuel up!

Darryl

Hi! My name is Darryl and this is my personal blog where I write about my journey as I learn programming! You'll also find articles about other things that interest me including games, tech and anime.

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

100 Days of SwiftUI – Day 65

100 Days of SwiftUI – Day 20 – Guess the Flag

100 Days of SwiftUI – Day 54

100 Days of SwiftUI – Day 33