一个可编辑、可拖拽的按钮和菜单栏,类似于 macOS 上 Safari 的收藏夹栏,支持溢出显示(macOS 10.11 及更高版本)。
一组按钮(项目)。如果空间不足以显示所有项目,则会出现一个“更多项目”按钮,其中包含隐藏的按钮。
此控件的灵感来自 Safari 的收藏夹栏。
self.actionBar.actionDelegate = self
// Add a simple 'job' button with a target/action
self.actionBar.add("Jobs", target: self, action: #selector(self.jobItem(_:)))
// Add a button with a drop-down menu
let menu = NSMenu()
menu.addItem(withTitle: "first", action: #selector(self.firstItem(_:)), keyEquivalent: "")
menu.addItem(withTitle: "second", action: #selector(self.secondItem(_:)), keyEquivalent: "")
menu.addItem(withTitle: "third", action: #selector(self.thirdItem(_:)), keyEquivalent: "")
self.actionBar.add("Ordering", menu: menu)
一组充当标签栏的按钮。 如果空间不足,则会出现一个“更多项目”按钮,其中包含“隐藏”的选项卡。
例如,查看 KeyChain Access 中的详细信息窗格 - “所有项目”、“密码”等。 此 KeyChain Access 应用程序部分地激发了这个控件 - 因为您会注意到,如果您将窗口调整为小于选项卡的大小,它只会绘制到屏幕外
// Set the delegate so that we receive tab selection messages
self.actionTabBar.actionTabDelegate = self
// Add our items
self.actionTabBar.add("All Items")
self.actionTabBar.add("Passwords")
self.actionTabBar.add("Secure Notes")
self.actionTabBar.add("My Certificates")
self.actionTabBar.add("Keys")
self.actionTabBar.add("Certificates")
...
extension MyViewController: DSFActionTabBarDelegate {
func actionTabBar(_ actionTabBar: DSFActionTabBar, didSelectItem item: DSFActionBarItem, atIndex index: Int) {
Swift.print("Selected tab \(index) for item '\(item.title)'")
}
}
您可以在 Demos
子文件夹中找到一些演示应用程序。
将 https://github.com/dagronf/DSFActionBar
添加到您的项目。
DSFActionBar
或 DSFActionTabBar
。let actionBar = DSFActionBar(frame: rect)
let tabBar = DSFActionTabBar(frame: rect)
MIT License
Copyright (c) 2021 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.