【发布时间】:2016-09-21 08:33:53
【问题描述】:
你好,我有一个简单的项目在我里面使用 UINavigationBar 里面 UIImageView 标志,但有些意见我的标志看起来 30-40px 右侧或一些意见看起来 50-60px 左侧?
如何设置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
输出图片;
此外,当我将 x:50 更改为 x:80 或 x:0 等时,什么也没发生!
【问题讨论】:
-
可以输出一些你需要什么类型的
-
尝试设置 x 原点 0
-
@kirtimali 我尝试设置为 0 但另一个视图看起来很糟糕
-
This relative question 可能会有所帮助。
-
如果你把frame origin设置为0会怎么样?这样它会在中心
标签: ios swift swift2 uinavigationbar swift3