swift - 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)
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?
解决方案
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
推荐阅读
- javascript - 一定距离沿折线的传单点
- java - 如何在 Exoplayer 中暂停/恢复视频?
- properties - “WFLYCTL0216:找不到管理资源”
- php - Laravel 5.4:api 密码重置 updateOrCreate
- inno-setup - 只允许一个 Inno Setup 实例而不提示
- javascript - 使用 vanilla JS 检测是否所有子项都被隐藏并隐藏父 div
- jquery - 使用 jquery 检查下拉值是否包含特定文本
- azure - 如何在 Microsoft Azure App Service 控制台中压缩/压缩文件?
- java - 如何在 Java 中手动编写 MD5(获取文件的哈希)算法?
- css - 如何在我的 html 页面中消除水平和垂直的多余空间