SwiftUI 文本行为 [英] SwiftUI Text Behavior

查看:29
本文介绍了SwiftUI 文本行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的设备上看到了一些我在模拟器中没有看到的奇怪的文本字段行为.我在 VStack 中有一个从 @ObservedObject 变量调用的标准文本字段分组,如下所示:

I am seeing some odd Text field behavior on my device that I did not see in the simulator. I have a standard grouping of text fields within a VStack that call from an @ObservedObject variable, like follows:

    @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)

        }

当变量发生变化时,我看到设备上的文本字段发生变化,但输出经常被截断为...,请参见下文.预先感谢您的帮助.

When the variable changes I see the text field change on the device but every so often the output is truncated into ..., please see below. Thank you in advance for your assistance.

推荐答案

我在旋转到横向时遇到了这个问题(即使有更多的水平空间.)我修复它的方法是调用 .fixedSize()Text 上.

I ran into this issue on rotation to landscape (even though there was more horizontal room.) The way I fixed it was to call .fixedSize() on the Text.

Text(timer.currentActivityName)
  .font(.largeTitle)
  .bold()
  .underline()
  .fixedSize()
  .padding(.bottom, 5)

确保在设置权重、字体等之后但在填充之前调用 fixedSize.

Make sure to do your fixedSize call after setting weight, font, etc. but before your padding.

这篇关于SwiftUI 文本行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆