小编Son*_*oni的帖子

使用 .aspectRatio(contentMode: .fill) 后文本会离开屏幕

我正在尝试使用 SwiftUI 制作一个带有背景图像的应用程序。然而,图像的宽高比与屏幕不同,这使得我习惯用.aspectRatio(contentMode: .fill)它来填充整个屏幕。在我开始添加文本之前,这工作完全正常。添加文本时,它现在会离开屏幕,而不是像通常那样换行。

\n

这是我的代码:

\n
struct FeaturesView: View\n{\n    var body: some View\n    {\n        ZStack\n        {\n            Image("background")\n                .resizable()\n                .aspectRatio(contentMode: .fill)\n                .edgesIgnoringSafeArea(.all)\n            \n            VStack(alignment: .leading)\n            {\n                Text("Hello this is some sample text that i am writing to show that this text goes off the screen.")\n            }\n            .foregroundColor(.white)\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是预览:

\n

预览

\n

正如您所看到的,文本从屏幕上消失了。我尝试使用 \xc2\xb4.frame()\xc2\xb4 并指定宽度和高度来修复它,但这会在其他视图中使用视图时导致问题。我正在使用 Xcode 12 beta。

\n

我是 Swift 和 SwiftUI 的新手,因此感谢所有帮助:)

\n

xcode swift swiftui

1
推荐指数
1
解决办法
1188
查看次数

标签 统计

swift ×1

swiftui ×1

xcode ×1