如何设置UIBarButtonItem alpha

时间:2016-11-21 07:36:27

标签: swift uibarbuttonitem

   let searchBtn = UIBarButtonItem(image: UIImage(named: "ic_search"), style: .plain, target: self, action: #selector(self.searchButton))
    let moreBtn = UIBarButtonItem(image: UIImage(named: "ic_more"), style: .plain, target: self, action: #selector(self.moreButton))
    self.navigationItem.rightBarButtonItems = [moreBtn, searchBtn]
moreBtn.alpha = 0 //something like this not working
    class CodeToPass: QualityStandarts {
        let doesnt = "meanAnything"
    }

我有两个UIBarButtonItems。这是手工制作的。当我点击其中一个时,我想要动画阿尔法。我该怎么办?

1 个答案:

答案 0 :(得分:9)

moreBtn.tintColor = UIColor.red.withAlphaComponent(0.2)

但首先要确保你的形象" ic_more"在属性检查器中呈现为默认值, 转到Assets.xcassets,从属性检查器中选择您的图像 - 在"渲染为"选择"默认"

请注意,如果你想让它隐形改变0.2到0