NSToolbar 只保留自定義工具欄選項
Updated 1:
According to @Khundragpan and [this post](https://stackoverflow.com/questions/8413111/how-to-customize-the-context-menu-of-nstoolbar), problem 1 can be solved by:
if let contextMenu = window?.contentView?.superview?.menu {
for item in contextMenu.items {
if item.title != "Customize Toolbar…" {
contextMenu.removeItem(item)
}
}
}
But I don't think it's the best way.
Update 2:
Another way to solve problem 1 (thanks to @1024jp to point out this file):
if let contextMenu = window?.contentView?.superview?.menu {
contextMenu.items.forEach({ (item) in
if let action = item.action,
NSStringFromSelector(action) != "runToolbarCustomizationPalette:" {
contextMenu.removeItem(item)
}
})
}
Update 3:
A ton of thanks to @1024jp for helping me. I'm able to remove those things with a few tips and tricks from him. Check the answer below.
You can access and modify a toolbar contextual menu when the toolbar is created, i.e. in -[awakeFromNib]:
- (NSMenu *)toolbarMenuInWindow:(NSWindow *)window{
NSView *contentView = window.contentView;
NSView *toolbarView = contentView.superview.subviews.lastObject;
NSMenu *toolbarMenu = toolbarView.menu;
return toolbarMenu;
}
Now you can directly edit menu items and hide or disable them.
相關文章
- UIWebView自定義選單欄UIWebView
- start11,自定義win11的選單欄和桌面欄工具
- 自定義 Windows 右鍵選單項Windows
- xmake高階特性之自定義選項
- Pandas高階教程之:自定義選項
- layUI Table自定義工具欄和搜尋引數UI
- DedeCMS的checkbox多選欄位自定義取值的方法
- Vue富文字帶圖片修改圖片大小自定義選擇項自定義字型Vue自定義字型
- 工具欄選單
- 自定義側邊快速索引欄索引
- Android 自定義標題欄Android
- uniapp自定義導航欄APP
- 自定義右鍵導航選單程式碼例項
- Vue element下拉框加一個自定義的選項Vue
- 微信小程式自定義導航欄微信小程式
- Request 增加自定義欄位的方式
- ios自定義簡約導航欄iOS
- JavaScript 側欄選項卡JavaScript
- 通過計算機語言自定義保留小數計算機
- 「Mac新手必備」自定義 Mac 上的控制中心和選單欄Mac
- element ui 自定義的快捷選項的日期選擇器並格式化UI
- css自定義單選按鈕的樣式程式碼例項CSS
- Android設定選項開發及自定義Preference樣式Android
- Android自定義TitleBar 自定義標題欄 並進行事件處理Android事件
- PhpCms自定義欄位的使用說明PHP
- laravel model自定義軟刪除欄位Laravel
- UWP中實現自定義標題欄
- MySQL 效能壓測工具,從入門到自定義測試項MySql
- 對選擇螢幕上的一個欄位設定自定義Search Help
- Prometheus Operator自定義監控項Prometheus
- java自定義異常例項1Java
- OC:自定義日期選擇器
- 自定義時間選擇器
- 使用PhotosKit自定義多選相簿
- Qt隱藏系統標題欄,使用自定義標題欄QT
- MySQL 效能壓測工具-sysbench,從入門到自定義測試項MySql
- Mybatis-plus排除自定義欄位不查詢MyBatis
- WordPress新增自定義sidebar側邊欄功能IDE