2016-09-21 37 views
0

你好我有簡單的項目裏面使用UINavigationBar裏面UIImageView標誌,但一些意見我的標誌看30-40px右側或一些意見看50-60px左側?如何設置navigationItem.titleView圖像的水平中心?

如何設置navigationItem.titleView圖像的水平中心?

我的代碼如下。

 navigationController!.navigationBar.barTintColor = UIColor.clearColor() 
     navigationController!.navigationBar.tintColor = UIColor.whiteColor(); 

     let imageView = UIImageView(frame: CGRect(x: 50, y: 0, width: 164, height: 38)) 
     imageView.contentMode = .ScaleAspectFit 
     let image = UIImage(named: "logo.png") 
     imageView.image = image 
     navigationItem.titleView = imageView 

輸出圖片;

enter image description here

而且當我改變x:50x:80x:0等..沒有發生的事情!

+0

可以耀一些輸出做ü需要 –

+0

1秒即時通訊做 – SwiftDeveloper

+1

嘗試設置x原點0 –

回答

1

你可以設置x原點0喜歡

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 164, height: 38)) 
+0

我嘗試設置0,但另一個視圖看起來不好 – SwiftDeveloper

+0

也如果我在那裏寫50或60看起來太糟糕了。 – SwiftDeveloper

+1

你能告訴我看起來不好看的另一個視圖 –

相關問題