Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 146 characters in body
Source Link
Anton
  • 1.8k
  • 16
  • 18

Create your own ButtonStyle:Set the button style to something different from the default, e.g., BorderlessButtonStyle()

 struct MyButtonStyleTest: ButtonStyleView {   funcvar makeBody(configurationbody: Configuration) -> some View { configuration.label .foregroundColor(.accentColor) .opacity(configuration.isPressed ? 0.5 : 1.0) }  } struct IdentifiableString: Identifiable {   let text: String var id: StringNavigationView { text } }  struct Test: ViewList {   var body: some View {  ListForEach([ IdentifiableString(text:  "Line 1"), IdentifiableString(text:  "Line 2"),   ], id: \.self) {   item in   HStack {   Text("\(item.text)")   Spacer()   Button(action: { print("\(item.text) 1")}) {   Text("Button 1")   }   Button(action: { print("\(item.text) 2")}) {   Text("Button 2") } } }   .onDelete { _ in } .buttonStyle(MyButtonStyleBorderlessButtonStyle())   }   .navigationBarItems(trailing: EditButton()) } .accentColor(.red) } } 

Create your own ButtonStyle:

 struct MyButtonStyle: ButtonStyle {   func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundColor(.accentColor) .opacity(configuration.isPressed ? 0.5 : 1.0) }  } struct IdentifiableString: Identifiable {   let text: String var id: String { text } }  struct Test: View {   var body: some View {  List([ IdentifiableString(text: "Line 1"), IdentifiableString(text: "Line 2"), ]) { item in HStack { Text("\(item.text)") Spacer() Button(action: { print("\(item.text) 1")}) { Text("Button 1") } Button(action: { print("\(item.text) 2")}) { Text("Button 2") } } }.buttonStyle(MyButtonStyle()) } } 

Set the button style to something different from the default, e.g., BorderlessButtonStyle()

struct Test: View { var body: some View { NavigationView { List { ForEach([   "Line 1",   "Line 2",   ], id: \.self) {   item in   HStack {   Text("\(item)")   Spacer()   Button(action: { print("\(item) 1")}) {   Text("Button 1")   }   Button(action: { print("\(item) 2")}) {   Text("Button 2") } } }   .onDelete { _ in } .buttonStyle(BorderlessButtonStyle())   }   .navigationBarItems(trailing: EditButton()) } .accentColor(.red) } } 
Source Link
Anton
  • 1.8k
  • 16
  • 18

Create your own ButtonStyle:

 struct MyButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundColor(.accentColor) .opacity(configuration.isPressed ? 0.5 : 1.0) } } struct IdentifiableString: Identifiable { let text: String var id: String { text } } struct Test: View { var body: some View { List([ IdentifiableString(text: "Line 1"), IdentifiableString(text: "Line 2"), ]) { item in HStack { Text("\(item.text)") Spacer() Button(action: { print("\(item.text) 1")}) { Text("Button 1") } Button(action: { print("\(item.text) 2")}) { Text("Button 2") } } }.buttonStyle(MyButtonStyle()) } }