[英]SwiftUI change EditButton Text Color
I am using Toolbar edit button to make the list edit, Below is the code I am using, I want to change the text color of EditButton(), there is no straight forward approach I found, Kindly help我正在使用工具栏编辑按钮进行列表编辑,下面是我正在使用的代码,我想更改 EditButton() 的文本颜色,我没有找到直接的方法,请帮忙
List {
ForEach(viewModel.datas) { data in
Text(data)
}
.onDelete { offset in
self.indexSetToDelete = offset
}
}
.toolbar {
EditButton()
// I want to set the edit button color
}
It is not possible to use accentColor if you Edit button in List, you have to set a navigation trail button and need to use environment editmode如果您在列表中编辑按钮,则无法使用重音颜色,您必须设置导航轨迹按钮并且需要使用环境编辑模式
@State private var editMode: EditMode = .inactive
var body: some View {
List {
ForEach(viewModel.datas) { data in
Text(data)
}
.onDelete { offset in
self.indexSetToDelete = offset
}
}.environment(\.editMode, $editMode)
.navigationBarItems(trailing: editButton) }
private var editButton: some View {
return Button {
if editMode == .inactive {
editMode = .active
} else {
editMode = .inactive
}
} label: {
Text(editMode == .inactive ? "Edit" : "Done")
.body(color: Color.red)
}
}
Use func .accentColor(Color)
使用 func
.accentColor(Color)
EditButton()
.accentColor(.red)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.