2016-09-21 42 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

你能告诉我看起来不好看的另一个视图 –

相关问题