struct ContentView: View {
@State private var isOdd: Bool = false
@State private var clickTimes: Int = 0
var body: some View {
Button {
isOdd.toggle()
clickTimes += 1
} label: {
Text("Hello, world!")
.opacity(
isOdd ? Double(clickTimes)/10.0 : 0.0
)
}
}
}
struct ContentView: View {
@State private var isOdd: Bool = false
@State private var clickTimes: Int = 0
var body: some View {
let opacity = if isOdd {
Double(clickTimes)/10.0
} else {
0.0
}
Button {
isOdd.toggle()
clickTimes += 1
} label: {
Text("Hello, world!")
.opacity(opacity)
}
}
}