在BarButtonItem Swift上添加徽章计数图标

时间:2018-07-30 07:30:34

标签: ios swift notifications badge

我想在UINavigationBar中使用的图标上添加徽章图标。

到目前为止,我已经完成了

let threeDotButton = UIBarButtonItem(image:UIImage(named: "ic_more.png")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(DashboardViewController.threeDotImageClick))
    let notificationButton = UIBarButtonItem(image:UIImage(named: "ic_notifications.png")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(DashboardViewController.notificationImageClick))
    self.tabBarController?.navigationItem.rightBarButtonItems = [threeDotButton,notificationButton]

    let title = UILabel()
    title.text = "Dashboard"
    self.tabBarController?.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: title)

    if let fontstyle = UIFont(name: "Roboto", size: 30) {
        self.tabBarController?.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: fontstyle]
    }

我想在通知按钮上添加计数徽章。我进行了搜索,但没有得到适当的解决方案。谁能解释我如何做到这一点

1 个答案:

答案 0 :(得分:0)

https://github.com/TanguyAladenise/BBBadgeBarButtonItem尝试使用此Pod,它可能满足您的要求,但是它是用目标C编写的,但是相当容易使用!!!