SwiftUI:文本字段被截断
我的SwiftUI应用程序上的文本字段被切断。但这并不是每次都会发生。这似乎是随机发生的 以下是我正在使用的代码:SwiftUI:文本字段被截断,swiftui,Swiftui,我的SwiftUI应用程序上的文本字段被切断。但这并不是每次都会发生。这似乎是随机发生的 以下是我正在使用的代码: var body: some View { VStack { Spacer() // Target row HStack { Text("Put the bullseye as close as you can to:") Text("\(target)") } Spacer()
var body: some View {
VStack {
Spacer()
// Target row
HStack {
Text("Put the bullseye as close as you can to:")
Text("\(target)")
}
Spacer()
// Slider row
HStack {
Text("1")
Slider(value: $sliderValue, in: 1...100) {_ in
print(self.sliderValue)
}
Text("100")
}
Spacer()
// Hit me button row
Button(action: {
print("Button pressed")
self.alertIsVisible = true
}) {
Text(/*@START_MENU_TOKEN@*/"Hit Me!"/*@END_MENU_TOKEN@*/)
}
.alert(isPresented: $alertIsVisible) { () -> Alert in
let roundedValue = Int(sliderValue.rounded())
let score = pointsForCurrentRound()
return Alert(title: Text("Hello there!"), message: Text("The slider's value is \(roundedValue)!\n" +
"You scored \(score) points this round"
), dismissButton: .default(Text("Awesome")))
}
Spacer()
// Score and start over button row
HStack {
Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) {
Text("Start Over")
}
Spacer()
Text("Score:")
Text("999999")
Spacer()
Text("Round:")
Text("999")
Spacer()
Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) {
Text("Info")
}
}
.padding(.bottom, 20)
}
}
我尝试在文本字段后面和目标之前添加填充。我试着在目标的前缘添加填充物。我尝试在文本字段中使用frame方法添加最小长度。这些都不管用。有什么想法吗
谢谢您可以添加fixedSize()来锁定标签
HStack {
Text("Put the bullseye as close as you can to:").fixedSize()
Text("\(target)").fixedSize()
}
我刚刚遇到了这种情况!经过几分钟的搜索、尝试和错误,我终于找到了答案。文本视图正在尝试调整大小,其中一个父视图已启用动画。如果有人在文本中添加了.animation(nil),这可能会解决问题
VStack {
Text("\(Int(self.viewModel.ProgressPercentage * 100.0))%")
.font(.largeTitle)
.animation(nil)
}
祝你好运 您使用的是哪个Xcode版本?我使用的是Xcode 11.1官方版本,我也参与过同一个项目,它在iOS 13.1及更高版本中得到了修复。感谢您的回复。我使用的是Xcode 11.2版,这是最新的版本。iOS 13.1及更高版本中固定了什么?啊,在iOS 13.1及更高版本中,文本根据其大小占用整个空间,而不是截断。你能告诉我什么时候它会在预览或模拟器/真实设备中随机发生吗?它会在预览和模拟器中发生。我还没有在真正的设备上试用过。我只是重新安装了11.1并试用了该应用程序。文本不再截断。所以一定是11.2里的东西。我将提交一份错误报告。谢谢你帮我做这件事。