如何在SwiftUI中给按钮添加多行文本?

6
如何声明Button结构以显示多行字符串?
   import SwiftUI

    struct ContentView : View {
        var body: some View {
            return Button("Line 1 \n Line 2") {}
        }
    }

ui

2个回答

4

你可以使用Button方法 lineLimit(_:)

struct ContentView : View {
    var body: some View {
          Button("Hello World").lineLimit(nil)
    }
}

您的代码返回错误 调用中缺少参数'label' - Jaydeep Vora

2
如果您想要多行的 Button,可以像这样实现。请参考以下代码:

 Button(action: {
          print("Action goes here")
       }, label: {
           Text("Line 1 \n Line 2").lineLimit(nil)
       })

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接