24: project 3, part 2

그루두·2024년 5월 6일
0

100 days of SwiftUI

목록 보기
33/108

100 days of swiftui: 24
https://www.hackingwithswift.com/100/swiftui/24

challenge

  1. 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.
  2. Go back to project 2 and 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.
  3. Create a custom ViewModifier (and accompanying View extension) that makes a view have a large, blue font suitable for prominent titles in a view.

solution

  1. 팁이 0%일 때 totalAmount를 빨강색으로 나타내기
                Section("Total amount") {
                    Text(totalAmount, format: .currency(code: "USD"))
                        .foregroundStyle(tipPercentage == 0 ? .red : .black)
                }

코드 파일
https://github.com/treesofgroo/Ios-WeSplit/commit/35c2f236d128f194eb265c6453dbdcca8ccd72e3

  1. flag를 FlagImage로 대체하기
// ...
                        Button {
                            guessFlag(selectedAnswer: number)
                        } label: {
                            FlagImage(flagName: countries[number])
                        }
// ...
struct FlagImage: View {
    let flagName: String
    var body: some View {            
        Image(flagName)
            .clipShape(RoundedRectangle(cornerRadius: 20))
            .shadow(radius: 10)
    }
}

코드 파일
https://github.com/treesofgroo/Ios-GuessFlags/commit/7449f18837ab0e6445e62f3794976bf7f7da6548

  1. 크고 파란색의 타이틀을 나타내는 ViewModifier 만들기
struct BlueTitle: ViewModifier {
    var text: String
    func body(content: Content) -> some View {
        VStack {
            Text(text)
                .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
                .foregroundStyle(.blue)
            content
        }
    }
}

extension View {
	// ... 
    func blueTitle(text: String) -> some View {
        modifier(BlueTitle(text: text))
    }
}

코드 파일
https://github.com/treesofgroo/Ios-studying/commit/8ebaed88dc93a89eb5139a55a64be3e2e8fbfabc

profile
계속 해보자

0개의 댓글

관련 채용 정보