0

I have a bar button item on my view controller which is showing a popover view, and I have an extension to show badges on any button, I tried to show the badges on the icon but it shows me another view, and I want to show the badges on my bar button item,

I tried this code

 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)
   }

my popover button code

 @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)
    }
}
 

currently it is showing like this! enter image description here

but I want the badges to be on my bar button not new button!

to clarify: the new bar button with badge is generated by the code in the question, and the comment button is mybutton which I want to show the badges on.

popover button is the button that I want to show the badges on instead of the generated button from the code

Jasmin_m
  • 1
  • 2
  • I don't understand the question. "I want the badges to be on my bar button not new button" -- what bar button do you mean; what new button do you mean? The screenshot shows a bar button with a badge, what would you expect instead? What has the PopOverController to do with the problem? – Andreas Oetjen Feb 11 '21 at 15:17
  • @AndreasOetjen the new bar button with badge is generated by the code in the question, and the comment button is mybutton which I want to show the badges on. – Jasmin_m Feb 11 '21 at 15:19
  • Again: What has the `showPopoverButtonAction` to do with the question? What is the "new bar button"? What is the "comment button"? I don't see any code regarding those, there is just a `bagButton` added to the right navigation item, but the image shows something else (there is a button on the left with a badge). Please refer to the code and show all the code. Maybe you also could create a image to show what you want. – Andreas Oetjen Feb 11 '21 at 15:33
  • @AndreasOetjen the popover button is the button that I want to show the badges on instead of the generated button from the code – Jasmin_m Feb 11 '21 at 15:42

0 Answers0