2017-01-16 115 views
0

我在navigationBar中存在titleview問題。事情是,當我將視圖分配給titleView時,它沒有顯示。我試過使用navigationItem.title = @"eqweqweq";,但沒有任何反應。navigationItem.TitleView無法在iOS 10上工作

涉及的這個視圖是由代碼創建的,我不知道這是否是問題,因爲我使用過的其他ViewControllers完美工作。

有沒有在iOS 10中的任何錯誤,我不能使用titleView?有時它有時不起作用。

我在谷歌搜索,但沒有幫助我。我希望有人能幫助我T_T。

謝謝

+1

如果您設置了titleView,則不會使用標題。你能不能展示一下你在做什麼的代碼? –

回答

0

只使用一個。

任一組的navigationItemtitleView象下面這樣:

UILabel *lblTitle = [[UILabel alloc] init]; 
lblTitle.text = @"eqweqweq"; 
lblTitle.backgroundColor = [UIColor clearColor]; 

[lblTitle sizeToFit]; 

self.navigationItem.titleView = lblTitle; 

OR

直接設置的navigationItemtitle象下面這樣:

[email protected]"eqweqweq" 
0

請試試這個。這個對我有用。

self.title = "eqweqweq" 

希望這將有助於周到,謝謝

0

最後我已經解決了這個問題!

的問題是這樣的功能:

extension UINavigationController{ 
func applyWhiteEffect(){ 
     var bounds = self.navigationBar.bounds 
     let whiteView = UIView() 
     bounds.origin.y = -20 
     bounds.size.height = bounds.size.height + 20 
     whiteView.frame = bounds 
     whiteView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 
     whiteView.userInteractionEnabled = false 
     whiteView.backgroundColor = UIColor.whiteColor() 
     whiteView.tag = 1000 
     self.navigationBar.addSubview(whiteView) 
     self.navigationBar.backgroundColor = UIColor.clearColor() 
     self.navigationBar.sendSubviewToBack(whiteView) 
    } 
} 

此函數施加的白色視圖和有與和iOS 10中的問題,所以我已經改變到這樣的:

func applyWhiteEffect(){ 
     var bounds = self.navigationBar.bounds 
     let whiteView = UIView() 
     bounds.origin.y = -20 
     bounds.size.height = 20 
     whiteView.frame = bounds 
     whiteView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 
     whiteView.userInteractionEnabled = false 
     whiteView.backgroundColor = UIColor.whiteColor() 
     whiteView.tag = 1000 
     self.navigationBar.addSubview(whiteView) 
     self.navigationBar.backgroundColor = UIColor.whiteColor() 
     self.navigationBar.sendSubviewToBack(whiteView) 
    } 

更改視圖只覆蓋狀態欄和self.navigationBar.backgroundColor = UIColor.whiteColor()

謝謝你們幫我:D

相關問題