2016-11-21 54 views
1
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。其中手動完成。我想動畫α,當我點擊其中的一個。我該怎麼做?如何設置UIBarButtonItem alpha

+0

意味着你想在一些按鈕上應用一些動畫,或者你想隱藏它在點擊搜索按鈕上。 –

回答

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

但首先要確保你的形象「ic_more」呈現爲默認的屬性檢查器中, 去Assets.xcassets,選擇你的形象和屬性檢查器 - 在「呈現爲」選擇「默認」

請注意,如果你想隱藏的變化0.2至0

+0

感謝我做了這樣的事情UIView.animate(withDuration:0.5,動畫:{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) } –

相關問題