本文介绍了如何在导航栏上使用图像徽标而不是标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几个不同的代码,但无法显示徽标

I have tried a couple different codes but couldn't make the logo show

import UIKit
class HomeViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image: logo)
self.navigationItem.titleView = imageView
navigationItem.titleView?.sizeToFit()
 }
}

我什至试图在课程中包含 IB 本身也没有用,它似乎不是那样工作

I even tried to include IB in the class itself didn't work either, it doesn't seem to work that way

@IBOutlet weak var navBar: UINavigationItem!

附注.我的徽标是一个 200x40px 的 png,它在资产中命名为 logo.png.

PS. My logo is a 200x40px png and its named logo.png in the assets.

我的故事板

http://i68.tinypic.com/b68t8o.png

感谢任何帮助

我通过在那里放置一个图像视图而不是整个导航项故事来解决我的问题.不过还是谢谢你的建议.

I solved my problem by putting an image view there instead of this whole navigation item story. Thanks for your suggestions though.

推荐答案

试试这个

 let logo = UIImage(named: "logo.png")
 let imageView = UIImageView(image: logo)
 imageView.contentMode = .ScaleAspectFit // set imageview's content mode
 self.navigationItem.titleView = imageView

这篇关于如何在导航栏上使用图像徽标而不是标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 14:00
查看更多