Blazej SLEBODA
Blazej SLEBODA

Reputation: 9925

How do you add multi-line text to a Button in SwiftUI?

How to declare Button struct to display multiline strings?

   import SwiftUI

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

ui

Upvotes: 6

Views: 4684

Answers (2)

Jaydeep Vora
Jaydeep Vora

Reputation: 6213

If you want multiline Button then you can implement it like this.

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

Upvotes: 3

RajeshKumar R
RajeshKumar R

Reputation: 15758

You can use Button method lineLimit(_:)

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

Upvotes: 4

Related Questions