使用按钮增加或减少Int。从正数变为负数或添加了事实10时,sizeToFit无法处理。
解决方案(?) 看起来这是预览和模拟器/设备之间的差异。也许我应该提起雷达...
struct ContentView:查看{ @State var totalClicked:Int = 0
var body: some View {
VStack {
HStack {
Button(action: {self.totalClicked = self.totalClicked - 1}) {
Text("decrease")
}
Button(action: {self.totalClicked = self.totalClicked + 1}) {
Text("increase")
}
}.padding()
Text("\(totalClicked)")
}
}