Skip to main content
Solutions should not be edited into the question, they should be added as answers
Source Link
Cristik
  • 33.2k
  • 26
  • 106
  • 143

EDIT: Turns out this is an issue with macOs.

- Issue with Buttons in SwiftUI on MacOS

EDIT 2: As Asmari mention below, you can use PlainButtonStyle:

    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               .frame(width: 100, height: 100)
               .foregroundColor(Color.black)
               .background(Color.red)
               .clipShape(Circle())
            }.buttonStyle(PlainButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

or use a custom style:

struct BlueButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .frame(width: 100, height: 100)
            .foregroundColor(Color.black)
            .background(Color.red)
            .clipShape(Circle())
    }
}

struct ContentView: View {
    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               
            }.buttonStyle(BlueButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

EDIT: Turns out this is an issue with macOs.

Issue with Buttons in SwiftUI on MacOS

EDIT 2: As Asmari mention below, you can use PlainButtonStyle:

    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               .frame(width: 100, height: 100)
               .foregroundColor(Color.black)
               .background(Color.red)
               .clipShape(Circle())
            }.buttonStyle(PlainButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

or use a custom style:

struct BlueButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .frame(width: 100, height: 100)
            .foregroundColor(Color.black)
            .background(Color.red)
            .clipShape(Circle())
    }
}

struct ContentView: View {
    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               
            }.buttonStyle(BlueButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

Turns out this is an issue with macOs - Issue with Buttons in SwiftUI on MacOS

deleted 65 characters in body; edited title
Source Link
Andy Jazz
  • 61k
  • 19
  • 166
  • 262

How can I make a simple circular button in SwiftUI in macOsmacOS?

        Button(action: {
        }){
            ZStack {
                Circle()
                .frame(width: 100, height: 100)
                .foregroundColor(.blue)
                Text("Press me")
            }
        }

How can I make a simple circular button in SwiftUI in macOs?

        Button(action: {
        }){
            ZStack{
                Circle()
                .frame(width: 100, height: 100)
                .foregroundColor(.blue)
                Text("Press me")
            }
        }

How can I make a simple circular button in SwiftUI in macOS?

Button(action: {
}){
    ZStack {
        Circle()
            .frame(width: 100, height: 100)
            .foregroundColor(.blue)
        Text("Press me")
    }
}
added 1201 characters in body
Source Link
ShadyAmoeba
  • 587
  • 1
  • 5
  • 16

EDIT 2: As Asmari mention below, you can use PlainButtonStyle:

    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               .frame(width: 100, height: 100)
               .foregroundColor(Color.black)
               .background(Color.red)
               .clipShape(Circle())
            }.buttonStyle(PlainButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

or use a custom style:

struct BlueButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .frame(width: 100, height: 100)
            .foregroundColor(Color.black)
            .background(Color.red)
            .clipShape(Circle())
    }
}

struct ContentView: View {
    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               
            }.buttonStyle(BlueButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

EDIT 2: As Asmari mention below, you can use PlainButtonStyle:

    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               .frame(width: 100, height: 100)
               .foregroundColor(Color.black)
               .background(Color.red)
               .clipShape(Circle())
            }.buttonStyle(PlainButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}

or use a custom style:

struct BlueButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .frame(width: 100, height: 100)
            .foregroundColor(Color.black)
            .background(Color.red)
            .clipShape(Circle())
    }
}

struct ContentView: View {
    var body: some View {
        VStack{
            Button(action: {
                print("Pressed!")
            }){
               Text("Press me")
               
            }.buttonStyle(BlueButtonStyle())
        }.frame(width: 300, height: 500)
        
    }
}
edited title
Link
ShadyAmoeba
  • 587
  • 1
  • 5
  • 16
Loading
Changing the iOS tag as the problem is specific to Mac OS.
Link
Loading
added 135 characters in body
Source Link
ShadyAmoeba
  • 587
  • 1
  • 5
  • 16
Loading
Source Link
ShadyAmoeba
  • 587
  • 1
  • 5
  • 16
Loading