dimanche 29 novembre 2020

How can I change a variable based on different booleans?

Can I know how to shorten this code?

I am trying to change the value of my Text only and I have written so many lines. Can I know how to change it and make it short?

if (selectedPage == OnboardingCard.last?.id) {
                                        Text("Get Started!")
                                            .foregroundColor(Color.white)
                                            .fontWeight(.bold)
                                            .padding(10)
                                            .padding(.horizontal)
                                            .background(Color.blue)
                                            .clipShape(Capsule())
                                    } else if (selectedPage == OnboardingCard.first?.id) {
                                        Text("Let's go!")
                                            .foregroundColor(Color.white)
                                            .fontWeight(.bold)
                                            .padding(11)
                                            .padding(.horizontal)
                                            .background(Color.blue)
                                            .clipShape(Capsule())
                                    } else {
                                        Text("Next")
                                        .foregroundColor(Color.white)
                                        .fontWeight(.bold)
                                        .padding(10)
                                        .padding(.horizontal)
                                        .background(Color.blue)
                                        .clipShape(Capsule())
                                    }

Aucun commentaire:

Enregistrer un commentaire