Skip to content

Latest commit

 

History

History
91 lines (64 loc) · 1.48 KB

README.md

File metadata and controls

91 lines (64 loc) · 1.48 KB

Button

import SwiftUI

struct ContentView: View {

    var body: some View {
        HStack {
            Button("Sign In", action: signIn)
            Button("Register", action: register)
        }
        .buttonStyle(.bordered)
    }
    
    func signIn() {}
    func register() {}
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

.buttonStyle(.automatic)

.buttonStyle(.plain)

Simple

Button("Tap me!") {
    print("Button was tapped")
}

Or

Button(action: {
    print("Button was tapped")
}) { 
    Text("Tap me!")
}

With image

Button(action: {
    print("Edit button was tapped")
}) { 
    Image(systemName: "pencil")
}

With image and text

Button(action: {
    print("Edit button was tapped")
}) {
    HStack(spacing: 10) { 
        Image(systemName: "pencil")
        Text("Edit")
    }
}

Tip: If you find that your images have become filled in with a color, for example showing as solid blue rather than your actual picture, this is probably SwiftUI coloring them to show that they are tappable. To fix the problem, use the renderingMode(.original) modifier to force SwiftUI to show the original image rather than the recolored version.

Links that help