我有一个UIViewController
,我从互联网加载一张图片,我想将其显示为导航标题 View 。
这是我从互联网获取图片后的代码
代码片段:
let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
imgView.backgroundColor = UIColor(red: 0.5, green: 0.5, blue: 0, alpha: 0.3)
imgView.image = result.image! //Contains the picture from internet
imgView.contentMode = .ScaleAspectFit
self.navigationItem.titleView = imgView
结果如下:
最佳答案
好的,我找到原因了。
所以 UIImageView 确实位于 titleView 的中心。 问题是 titleView 未居中,因为在我的情况下,左栏按钮项目比右栏按钮项目大。
我必须将两个栏按钮项目设置为相同的宽度,现在我的 titleView 居中。
关于ios - 导航标题 UIImageView 无法居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39592977/