【发布时间】:2021-03-12 02:34:51
【问题描述】:
我可以知道如何缩短这段代码吗?
我正在尝试仅更改Text 的值,并且我已经写了很多行。我可以知道如何更改它并使其简短吗?
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())
}
【问题讨论】:
-
你真的需要
.padding(11)和.padding(10)吗? -
只有一个没问题
标签: ios swift if-statement swiftui boolean