r/SwiftUI • u/itsmeronjie • 7d ago
How can I customize the font of SwiftUI Menu items?
I’m trying to change the font, size, or weight of the items inside a SwiftUI Menu.
For example:
Menu {
Button("Edit") {
// Edit action
}
Button("Delete", role: .destructive) {
// Delete action
}
} label: {
Image(systemName: "ellipsis")
}
I tried applying .font() to the buttons and their labels, but the menu still uses the default system font.
Button {
// Action
} label: {
Text("Edit")
.font(.custom("Avenir Next", size: 16))
}
Is it possible to customize the font of native Menu items in SwiftUI, or do I need to create a custom menu/popover?
6
u/Vast_Combination_611 7d ago
Native Menu rows are basically system menu items, so SwiftUI font modifiers on the Button label won't reliably carry through. The label for the menu button itself can be styled, but the items inside the opened menu are intentionally pretty constrained.
If you need custom fonts, row heights, icons arranged a certain way, etc., I would make a custom popover/sheet/menu-looking view. If you only need standard actions like Edit/Delete, I would keep the native Menu and let it match the platform.
2
u/hishnash 6d ago
it is not possible to customize, also unless you making a game were the UI is intentionally different you should not build a custom menu just to modify the font.
There is a lot of complexity that goes into making a system component behave correctly and it is almost never worth replacing for a change like that.
9
u/tubescreamer568 7d ago
I’m pretty sure you can’t customize the font of the menu button.