ios - 我如何在 swift ios 的导航栏标题中使用图像

标签 ios swift uinavigationbar

我有麻烦了。我想在导航栏标题中使用图像,但出现错误,即“UIImage”不是“NSString”的子类型。下面的代码,看吧。

class Dashboard: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.title = UIImage(named: "logo.png")        
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

有人可以推荐吗?谢谢!

最佳答案

设置navigationItem的titleView

var image = UIImage(named: "logo.png")
self.navigationItem.titleView = UIImageView(image: image)

关于ios - 我如何在 swift ios 的导航栏标题中使用图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26690904/

相关文章:

ios - 如何在出现时以编程方式触发 NavigationLink

ios - iOS 上的 OpenCV ZXing 不兼容

ios - 将工具栏添加到 Storyboard 中的 ViewController

ios - UICollectionViewCell 中的 UILabel 有时大小不正确

swift - MCSessionState 从连接状态变为未连接状态

ios - Swift 3 时间变化时如何执行操作

uitableview - 用 UIToolBar 替换 UITabBar

IOS/objective-C : Custom Segue Effect on Navigation Bar Compared with Show Segue

ios - 当用户导航更深时,UINavigationBar 将变为透明

iphone - iTunes 连接版本摘要页面上的 "Territory"是什么