OS X开发.第一章,1.11,NSPopupButton

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

运行图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值