RXP*_*RXP 6 ios swift5 swiftui
我在导航栏的前缘和后缘有菜单项。我无法更改菜单项的颜色。但是,我可以更改导航栏本身图标的颜色,但不能更改导航栏下方的菜单项。例如,我希望“删除”显示为红色。我尝试创建一个 ConfigurationStyle 但没有成功。
我的每一侧都有两个菜单项: 在前缘,我有“新建”和“编辑”,并尝试将颜色更改为绿色 在后缘,我有“添加”和“删除”
我究竟做错了什么?很感谢任何形式的帮助。谢谢。
这是我想要做的示例代码。
struct HomeView: View {
var body: some View {
NavigationView {
Text("Hello World")
.navigationTitle("Title")
.navigationBarItems(leading: {
Menu {
Button(action: {}) {
Label {
Text("New")
} icon: {
Image(systemName: "pencil")
}
}.foregroundColor(.green) //tried on the Menu item but does not work
Button(action: {}) {
Label {
Text("Edit").foregroundColor(.green) //tried to change color for individual elements (does not work)
} icon: {
Image(systemName: "square.and.pencil") // tried to change just for the image (does not work)
.foregroundColor(.green)
}
}
} label: {
Image(systemName: "ellipsis.circle").foregroundColor(.green) //this works!!!
}
}(), trailing: {
Menu {
Button(action: { }) { // tried to change color on the whole button with a MenuStyle (does not work)
Label("Add", systemImage: "plus")
}.menuStyle(RedMenu())
Button(action: { }) {
Label("Delete", systemImage: "trash") // tried to change the color on the Label (does not work)
.foregroundColor(.red)
}
} label: {
Image(systemName: "plus")
}
}())
}
.navigationBarTitleDisplayMode(.inline)
.navigationViewStyle(StackNavigationViewStyle())
}
}
Run Code Online (Sandbox Code Playgroud)
尝试使用 MenuStyle 但没有运气
struct RedMenu: MenuStyle {
func makeBody(configuration: Configuration) -> some View {
Menu(configuration)
.foregroundColor(.red)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
393 次 |
| 最近记录: |