即使在设置了.lineLimit(nil)之后,文本也不会换行.

var body: some View {
    VStack(alignment: .center) {
        Text("SwiftUI is a modern way to declare user interfaces for any Apple platform. ")
            .font(.title)
            .color(.red)
            .lineLimit(nil)
        Text("Create beautiful, dynamic apps faster than ever before.")
            .font(.system(size: 20))
            .lineLimit(nil)
    }.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}

enter image description here

推荐答案

try 将第二个文本的lineLimit改为一个数字,而不是零:

VStack(alignment: .leading) {
  Text("SwiftUI is a modern way to declare user interfaces for any Apple platform. ")
    .font(.title)
    .color(.red)
    .lineLimit(nil)
  Text("Create beautiful, dynamic apps faster than ever before.")
    .font(.system(size: 20))
    .lineLimit(2)
 }.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))

结果:

enter image description here

Ios相关问答推荐

在带有可编码的SWIFT5中,可以轻松处理以美元符号开头的JSON密钥,例如$DATE";

如何让3张组合的`SF Symbol`图片围绕一个特定点旋转?

如何使用Xcode15.1在iMessage扩展模块中显示贴纸

SwiftData共享扩展阻止应用程序打开SQLite文件

如何在 Swift 中存储具有关联值的协议?

如何使用 SwiftData 从列表中删除子项目?

如何在SwiftUI中实现淡入淡出加粘标题屏幕效果

iOS 16.4 更新后 Xcode 14.3 构建错误:找不到 libarclite_iphoneos.a,链接器命令失败

如何使用 AppIntents 在 SwiftUI 应用程序中打开特定视图

实现一个将块用作回调的方法

'+entityForName: nil 不是合法的 NSManagedObjectContext 参数 - 核心数据

通过touch 传递到下面的 UIViews

如何从一个特定的视图控制器中隐藏导航栏

如何使用 sendAsynchronousRequest:queue:completionHandler:

没有 Mac 的 Xamarin Visual Studio IOS 开发?

interfaceOrientation在 iOS 8 中已弃用,如何更改此方法 Objective C

在 iOS 上存储身份验证令牌 - NSUserDefaults 与 keys 串?

NSURLSession:如何增加 URL 请求的超时时间?

使用 swift 从应用程序委托打开视图控制器

UINavigationBar - 以编程方式设置标题?