Swift 2 - iOS:禁用条形按钮

时间:2016-08-29 11:22:57

标签: ios swift uibarbuttonitem

在下面的代码中,我使用swift 2创建了2个右键。

此刻,我想做出类似的事情:

accountButton.disable = false

但这是不可能的。

禁用此栏按钮的最佳解决方案是什么?

let accountImage   = UIImage(named: "account")!
let settingImage   = UIImage(named: "setting")!
let accountButton  = UIBarButtonItem(image: accountImage,  style: .Plain , target: self, action: "didTapEditButton:")

let settingButton  = UIBarButtonItem(image: settingImage,  style: .Plain, target: self, action: "didTapSearchButton:")

navigationItem.rightBarButtonItems = [accountButton , settingButton]

2 个答案:

答案 0 :(得分:4)

尝试:

Swift 2

accountButton.enabled = false

Swift 3

accountButton.isEnabled = false

答案 1 :(得分:0)

使用UIBarButtonItem的属性enabled代替disable