在带有操作的栏按钮项上显示徽章

问题描述

我的视图控制器上有一个条形按钮项,它显示一个弹出视图,我有一个扩展程序可以在任何按钮上显示徽章, 我试图在图标上显示徽章,但它向我显示了另一个视图,我想在我的栏按钮项目上显示徽章,

我试过这个代码

 func addBadge(itemvalue: String) {

       let bagButton = BadgeButton()
       bagButton.frame = CGRect(x: 0,y: 0,width: 44,height: 44)
       bagButton.tintColor = UIColor.darkGray
       bagButton.setimage(UIImage(named: "comment")?.withRenderingMode(.alwaystemplate),for: .normal)
       bagButton.badgeEdgeInsets = UIEdgeInsets(top: 20,left: 0,bottom: 0,right: 15)
       bagButton.badge = itemvalue
       self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: bagButton)
   }

我的弹窗按钮代码

 @IBAction func showPopoverButtonAction(_ sender: Any) {
    

    //get the button frame
    /* 1 */
    let button = sender as? UIButton
    let buttonFrame = button?.frame ?? CGRect.init(x: -20,y: -320,width: 200,height: 400)
 
    /* 2 */
    //Configure the presentation controller
    guard let popoverContentController = self.storyboard?.instantiateViewController(withIdentifier: "PopOverViewController") as? PopOverViewController else { return }
    popoverContentController.modalPresentationStyle = .popover

    popoverContentController.dpostID = self.postIdm
    popoverContentController.dpostTitle = self.postTitlem
    popoverContentController.duserPhone = self.muserPhone
    popoverContentController.delegate = self

    /* 3 */
    if let popoverPresentationController = popoverContentController.popoverPresentationController {
        popoverPresentationController.permittedArrowDirections = .up
        popoverPresentationController.sourceView = self.view
        popoverPresentationController.sourceRect = buttonFrame
        popoverPresentationController.delegate = self
    //    if let popoverController = popoverContentController {
    //
    //    }
        present(popoverContentController,animated: true,completion: nil)
    }
}
 

目前是这样显示的! enter image description here

但我希望徽章在我的栏按钮上而不是新按钮上!

澄清:带有徽章的新栏按钮是由问题中的代码生成的,而评论按钮是我想在其上显示徽章的 mybutton。

popover button 是我想要显示徽章的按钮,而不是代码生成的按钮

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)