1.11 NSPopupButton
NSPopupButton是Cocoa中弹出式选择控件
1.11.1 基本声明
var popupButton: NSPopUpButton!
popupButton = NSPopUpButton(frame: NSRect(x: (self.view.frame.width / 2) - 50, y: 150, width: 100, height: 29))
popupButton.addItems(withTitles: ["Spring", "SpringBoot", "JPA", "Redis", "ActiveMQ"])
popupButton.target = self
popupButton.action = #selector(popupButtonListener)
self.view.addSubview(popupButton)
@objc func popupButtonListener(){
let getArray = popupButton.itemTitles
print("------> CLICK AT:\(getArray[popupButton.indexOfSelectedItem])")
}
1.11.2方法或属性
1.动态增加Item
-
func addItem(withTitle: String)
将具有指定标题的项目添加到菜单的末尾。 -
func insertItem(withTitle: String, at: Int)
在菜单中的指定位置插入一个项目。
2.动态删除Item
-
func removeAllItems()
删除接收器项目菜单中的所有项目。 -
func removeItem(withTitle: String)
从菜单中删除具有指定标题的项目。 -
func removeItem(at: Int)
删除指定索引的item
3.是否表现为下拉菜单或弹出菜单
pullsDown属性设为true或false
运行图: