首页 > 解决方案 > add a text to navigation bar item

问题描述

I need to write a number on top of one of my navigation bar items ( on the shopping cart picture) enter image description here

I tried to connect it with an outlet and using this code but it didn't work.

  self.BtnSabadNav.title = "3"

I also tried this code but it didn't work too.

self.navigationItem.leftBarButtonItem?.title = "fdf"

how should I do this?

标签: swiftxcodeuinavigationcontroller

解决方案


You would need to have a custom UIView which would contain a UIImage and UILabel. Then you need to set the custom view to the UIBarBarButtonItem.

let barButtonItem = UIBarButtonItem(customView: yourCustomView)
self.navigationItem.leftBarButtonItem = barButtonItem

推荐阅读