如何设置UIBarButtonItem的透明度

8
   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,它们是手动创建的。当我点击其中一个时,我想要对其进行透明度动画处理。我该如何实现?


你想在“更多”按钮上应用一些动画效果,或者你想在点击搜索按钮后隐藏它。 - Sumit Jangra
1个回答

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

但首先请确保您的图像「ic_more」在属性检查器中以默认方式呈现,进入Assets.xcassets,选择您的图像,然后从属性检查器中,在「Renders As」下选择「Default」。

请注意,如果您想让它��可见,请将0.2更改为0。


谢谢,我做了类似这样的事情:UIView.animate(withDuration: 0.5, animations: { self.navigationItem.rightBarButtonItems?[0].tintColor = UIColor.red.withAlphaComponent(0.0) self.navigationItem.rightBarButtonItems?[0].tintColor = UIColor.green.withAlphaComponent(0.0) self.navigationItem.rightBarButtonItems?[0].tintColor = UIColor.blue.withAlphaComponent(0.0) }) - Nikolay Borisov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接