On Windows平台,与VCL,当我们想要添加一个分隔器在菜单中,我们添加一个TMenuItem
with a Caption := '-'
;
With 火猴,我们添加一个TMenuItem
with a Text := '-'
;
它在 Windows 平台上按预期工作,带有 Text='-' 的项目显示为分隔符。
但是,当我在上运行相同的应用程序时OSX,我看到减号可见......
我还没有找到任何财产TMenuItem
指定它是一个分隔器...
我尝试过TMainMenu
and a TMenuBar
(UseOSMenu := True|False;
),我仍然有这个问题。
有想法创建一个真正的分隔符吗?(否则,我将检查操作系统并删除它,如果 OSX...)
这是 FireMonkey 中的一个错误。我相信他们会解决这个问题。但同时您可以使用下面的代码。在主窗体的 OnActivate 事件中调用过程 FixSeparatorItemsForMac。
不要忘记使用列表中的 mac 特定文件。
uses
...
{$IFDEF MACOS}
,Macapi.ObjectiveC,MacApi.AppKit,MacApi.Foundation,FMX.Platform.Mac
{$ENDIF}
{$IFDEF MACOS}
Procedure FixSeparatorItemsForMenuItem(MenuItem:NSMenuItem);
var i:Integer;
subItem:NSMenuItem;
begin
if (MenuItem.hasSubmenu = false) then exit;
for i := 0 to MenuItem.submenu.itemArray.count -1 do
begin
subItem := MenuItem.submenu.itemAtIndex(i);
if (subItem.title.isEqualToString(NSSTR('-'))= true) then
begin
MenuItem.submenu.removeItemAtIndex(i);
MenuItem.submenu.insertItem(TNSMenuItem.Wrap(TNSMenuItem.OCClass.separatorItem),i);
end else begin
FixSeparatorItemsForMenuItem(subItem);
end;
end;
end;
Procedure FixSeparatorItemsForMac;
var NSApp:NSApplication;
MainMenu:NSMenu;
AppItem: NSMenuItem;
i: Integer;
begin
NSApp := TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication);
MainMenu := NSApp.mainMenu;
if (MainMenu <> nil) then
begin
for i := 0 to MainMenu.itemArray.count -1 do
begin
AppItem := mainMenu.itemAtIndex(i);
FixSeparatorItemsForMenuItem(AppItem);
end;
end;
end;
{$ENDIF}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)