我有2个条形项目,如下图所示当我点击第一个时,如何隐藏第二个? (我试过earthBtn.hidden = true但它没有用。这是我的代码:
let earthImg = UIImage(named: "earth0")
let earthBtn = UIBarButtonItem(image: earthImg, style: .Plain, target: self, action: "earthBtn_click")
let messageImg = UIImage(named: "categories1")
let messageBtn = UIBarButtonItem(image: messageImg, style: .Plain, target: self, action: "messageBtn_click")
let buttonArray = NSArray(objects: earthBtn,messageBtn)
self.navigationItem.rightBarButtonItems = buttonArray as? [UIBarButtonItem]
func messageBtn_click() {
earthBtn.hidden = true // is not working
}
谢谢你。
答案 0 :(得分:1)
好吧,你无法隐藏UIBarButtonItem
,你可以做的是使颜色透明并禁用它,当你想要使用它然后你必须启用它然后给它一个颜色:
将其全局定义为类变量:
let earthBtn = UIBarButtonItem()
使用它像:
earthBtn = UIBarButtonItem(image: earthImg, style: .Plain, target: self, action: "earthBtn_click")
隐藏按钮:
func messageBtn_click() {
earthBtn.enabled = false
earthBtn.color = UIColor.clearColor()
}