How to set UIBarButtonItem alpha

不想你离开。 提交于 2019-12-07 02:25:37

问题


   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"
    }

I have two UIBarButtonItems. Which made manually. And i wanna animate alpha, when i click one of them. How can i do it?


回答1:


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

but first make sure your image "ic_more" renders as default in the attributes inspector, go to Assets.xcassets, select your image and from attributes inspector - under "Renders As" select "Default"

note that if you want it invisible change 0.2 to 0



来源:https://stackoverflow.com/questions/40714950/how-to-set-uibarbuttonitem-alpha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!