swift - SwiftUI 文本行为
问题描述
我在我的设备上看到了一些在模拟器中没有看到的奇怪的文本字段行为。我在从 @ObservedObject 变量调用的 VStack 中有一个标准的文本字段分组,如下所示:
@ObservedObject var timer: ActivityTimer
var body: some View {
VStack {
VStack {
Text(timer.currentCountdownString).font(Font.system(size: 90))
Text(timer.currentActivityName).font(.largeTitle).bold().underline().padding(.bottom, 5)
Text(timer.currentIncline).font(.title)
}
.padding()
.cornerRadius(10)
}
当变量发生变化时,我看到设备上的文本字段发生变化,但输出经常被截断为...,请参见下文。预先感谢您的协助。
解决方案
我在旋转到横向时遇到了这个问题(即使有更多的水平空间。)我修复它的方法是调用.fixedSize()
.Text
Text(timer.currentActivityName)
.font(.largeTitle)
.bold()
.underline()
.fixedSize()
.padding(.bottom, 5)
确保在设置权重、字体等之后但在填充之前进行 fixedSize 调用。
推荐阅读
- java - HTMLUnit input.click() 没有返回点击应该加载的站点
- java - 如何针对其中的两个元素(两列)对类型为类的数组列表进行排序
- javascript - 如何修复 Seek Command 使歌曲回到开头 - Discord.js
- json - 如何使用相同的键在嵌套的 json 对象中构造数组
- android - 签署与 AAB 相同的 APK
- java - jgit 在使用 Git.cloneRepository 时发生 Packfile 被截断
- beautifulsoup - 从巴西网站抓取 ISBN 信息
- javascript - 在 react js useState() 钩子中更改多个状态
- c++ - C++中“&”位运算符的酉数
- python - PyTorch 中的 index_select 和 tensor[sequence] 之间有什么区别吗?