当长度属性更改时,SwiftUI文本不适合

时间:2019-06-10 10:37:03

标签: text swiftui sizetofit

使用按钮增加或减少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)")


    }
}

} enter image description here

enter image description here

enter image description here enter image description here

模拟器<->预览差异 enter image description here

0 个答案:

没有答案