Apply custom fonts and colors to context menus

I am looking for a way to apply custom fonts and colors to context menus. I was able to change UIAction text color with the appearance manager:


[[[UILabel class] appearanceWhenContainedInInstancesOfClasses:@[NSClassFromString(@"_UIContextMenuActionView")]] setTextColor:[UIColor greenColor]];

But doing the same with the font does not work for me:


[[[UILabel class] appearanceWhenContainedInInstancesOfClasses:@[NSClassFromString(@"_UIContextMenuActionView")]] setFont:[UIFont systemFontOfSize:30]];

Similarly I cannot find a way to apply custom colors to the separator lines between UIActions or inline UIMenus.


Is there a way to do this?


Thanks.


John

Replies

+1 for this. In AppKIt NSMenuItem can take an attributedString. Would be nice to have equivalent API here.

In SwiftUI 2.0 you can add role to the buttons of the context menu.

Follow this thread for more information.